Void Linux discussion
 help / Atom feed
* Fix for chsh (util-linux)
@ 2019-09-22 13:12 Quentin Rameau
  2019-09-22 13:12 ` [PATCH 1/2] lib/pwdutils: add xgetpwuid Quentin Rameau
  2019-09-22 13:12 ` [PATCH 2/2] chsh: replace getpw unsafe functions with xgetpw Quentin Rameau
  0 siblings, 2 replies; 3+ messages in thread
From: Quentin Rameau @ 2019-09-22 13:12 UTC (permalink / raw)
  To: Void Linux

Hello,

There is an issue with chsh when trying to modify another user as
root, it will just modify root instead of target user.

The fix(es) have been sent upstream, I just put it here too waiting
for upstream to merge it and make a new release.


-- 
You received this message because you are subscribed to the Google Groups "voidlinux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to voidlinux+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/voidlinux/20190922131237.93849-1-quinq%40fifth.space.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] lib/pwdutils: add xgetpwuid
  2019-09-22 13:12 Fix for chsh (util-linux) Quentin Rameau
@ 2019-09-22 13:12 ` Quentin Rameau
  2019-09-22 13:12 ` [PATCH 2/2] chsh: replace getpw unsafe functions with xgetpw Quentin Rameau
  1 sibling, 0 replies; 3+ messages in thread
From: Quentin Rameau @ 2019-09-22 13:12 UTC (permalink / raw)
  To: Void Linux; +Cc: Quentin Rameau

---
 include/pwdutils.h |  1 +
 lib/pwdutils.c     | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/include/pwdutils.h b/include/pwdutils.h
index a69dd6b45..bea46e57e 100644
--- a/include/pwdutils.h
+++ b/include/pwdutils.h
@@ -5,6 +5,7 @@
 #include <pwd.h>
 
 extern struct passwd *xgetpwnam(const char *username, char **pwdbuf);
+extern struct passwd *xgetpwuid(uid_t uid, char **pwdbuf);
 extern char *xgetlogin(void);
 
 #endif /* UTIL_LINUX_PWDUTILS_H */
diff --git a/lib/pwdutils.c b/lib/pwdutils.c
index 25b4daed0..d54458d65 100644
--- a/lib/pwdutils.c
+++ b/lib/pwdutils.c
@@ -36,6 +36,34 @@ failed:
 	return NULL;
 }
 
+struct passwd *xgetpwuid(uid_t uid, char **pwdbuf)
+{
+	struct passwd *pwd = NULL, *res = NULL;
+	int rc;
+
+	if (!pwdbuf)
+		return NULL;
+
+	*pwdbuf = xmalloc(UL_GETPW_BUFSIZ);
+	pwd = xcalloc(1, sizeof(struct passwd));
+
+	errno = 0;
+	rc = getpwuid_r(uid, pwd, *pwdbuf, UL_GETPW_BUFSIZ, &res);
+	if (rc != 0) {
+		errno = rc;
+		goto failed;
+	}
+	if (!res) {
+		errno = EINVAL;
+		goto failed;
+	}
+	return pwd;
+failed:
+	free(pwd);
+	free(*pwdbuf);
+	return NULL;
+}
+
 char *xgetlogin(void)
 {
 	struct passwd *pw = NULL;
-- 
2.21.0

-- 
You received this message because you are subscribed to the Google Groups "voidlinux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to voidlinux+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/voidlinux/20190922131237.93849-2-quinq%40fifth.space.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] chsh: replace getpw unsafe functions with xgetpw
  2019-09-22 13:12 Fix for chsh (util-linux) Quentin Rameau
  2019-09-22 13:12 ` [PATCH 1/2] lib/pwdutils: add xgetpwuid Quentin Rameau
@ 2019-09-22 13:12 ` Quentin Rameau
  1 sibling, 0 replies; 3+ messages in thread
From: Quentin Rameau @ 2019-09-22 13:12 UTC (permalink / raw)
  To: Void Linux; +Cc: Quentin Rameau

---
 login-utils/chsh.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/login-utils/chsh.c b/login-utils/chsh.c
index 9b2761157..a9ebec86f 100644
--- a/login-utils/chsh.c
+++ b/login-utils/chsh.c
@@ -38,6 +38,7 @@
 #include "islocal.h"
 #include "nls.h"
 #include "pathnames.h"
+#include "pwdutils.h"
 #include "setpwnam.h"
 #include "strutils.h"
 #include "xalloc.h"
@@ -253,7 +254,7 @@ static void check_shell(const char *shell)
 
 int main(int argc, char **argv)
 {
-	char *oldshell;
+	char *oldshell, *pwbuf;
 	int nullshell = 0;
 	const uid_t uid = getuid();
 	struct sinfo info = { NULL };
@@ -267,12 +268,12 @@ int main(int argc, char **argv)
 
 	parse_argv(argc, argv, &info);
 	if (!info.username) {
-		pw = getpwuid(uid);
+		pw = xgetpwuid(uid, &pwbuf);
 		if (!pw)
 			errx(EXIT_FAILURE, _("you (user %d) don't exist."),
 			     uid);
 	} else {
-		pw = getpwnam(info.username);
+		pw = xgetpwnam(info.username, &pwbuf);
 		if (!pw)
 			errx(EXIT_FAILURE, _("user \"%s\" does not exist."),
 			     info.username);
-- 
2.21.0

-- 
You received this message because you are subscribed to the Google Groups "voidlinux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to voidlinux+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/voidlinux/20190922131237.93849-3-quinq%40fifth.space.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-22 13:12 Fix for chsh (util-linux) Quentin Rameau
2019-09-22 13:12 ` [PATCH 1/2] lib/pwdutils: add xgetpwuid Quentin Rameau
2019-09-22 13:12 ` [PATCH 2/2] chsh: replace getpw unsafe functions with xgetpw Quentin Rameau

Void Linux discussion

Archives are clonable: git clone --mirror http://inbox.vuxu.org/voidlinux

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.voidlinux


AGPL code for this site: git clone https://public-inbox.org/ public-inbox