public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Cody Maloney <cmaloney@theoreticalchaos.com>
To: util-linux@vger.kernel.org
Cc: mitr@redhat.com, Cody Maloney <cmaloney@theoreticalchaos.com>
Subject: [PATCH v2 4/4] chfn: Add libuser support
Date: Sun, 13 Jan 2013 02:12:25 -0700	[thread overview]
Message-ID: <1358068345-773-6-git-send-email-cmaloney@theoreticalchaos.com> (raw)
In-Reply-To: <1358068345-773-1-git-send-email-cmaloney@theoreticalchaos.com>


Signed-off-by: Cody Maloney <cmaloney@theoreticalchaos.com>
---
 login-utils/chfn.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/login-utils/chfn.c b/login-utils/chfn.c
index e189558..80abefa 100644
--- a/login-utils/chfn.c
+++ b/login-utils/chfn.c
@@ -1,6 +1,7 @@
 /*
  *   chfn.c -- change your finger information
  *   (c) 1994 by salvatore valente <svalente@athena.mit.edu>
+ *   (c) 2012 by Cody Maloney <cmaloney@theoreticalchaos.com>
  *
  *   this program is free software.  you can redistribute it and
  *   modify it under the terms of the gnu general public license.
@@ -31,7 +32,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include "auth.h"
 #include "c.h"
 #include "env.h"
 #include "closestream.h"
@@ -47,6 +47,13 @@
 # include "selinux_utils.h"
 #endif
 
+#ifdef HAVE_LIBUSER
+# include <libuser/user.h>
+# include "libuser.h"
+#else
+# include "auth.h"
+#endif
+
 static char buf[1024];
 
 struct finfo {
@@ -149,17 +156,24 @@ int main(int argc, char **argv)
 	}
 #endif
 
-	/* Reality check */
-	if (uid != 0 && uid != oldf.pw->pw_uid) {
+#ifdef HAVE_LIBUSER
+	/* If we're setuid and not really root, disallow the password change. */
+	if (geteuid() != getuid() && uid != pw->pw_uid) {
+#else
+	if (uid != 0 && uid != pw->pw_uid) {
+#endif
 		errno = EACCES;
-		err(EXIT_FAILURE, NULL);
+		err(EXIT_FAILURE, _("running UID doesn't match UID of user we're "
+		      "altering, change denied")););
 	}
 
 	printf(_("Changing finger information for %s.\n"), oldf.username);
 
+#ifndef HAVE_LIBUSER
 	if(!auth_pam("chfn", uid, oldf.username)) {
 		return EXIT_FAILURE;
 	}
+#endif
 
 	if (interactive)
 		ask_info(&oldf, &newf);
@@ -445,9 +459,14 @@ static int save_new_data(struct finfo *pinfo)
 		gecos[len] = 0;
 	}
 
+#ifdef HAVE_LIBUSER
+	if(set_value_libuser("chfn", pinfo->pw->pw_name, pinfo->pw->pw_uid,
+			LU_GECOS, gecos)) {
+#else /* HAVE_LIBUSER */
 	/* write the new struct passwd to the passwd file. */
 	pinfo->pw->pw_gecos = gecos;
 	if (setpwnam(pinfo->pw) < 0) {
+#endif
 		warn("setpwnam");
 		printf(_
 		       ("Finger information *NOT* changed.  Try again later.\n"));
-- 
1.8.1


  parent reply	other threads:[~2013-01-13  9:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-13  9:12 [PATCH v2 0/4] Add support for using libuser to chsh and chfn Cody Maloney
2013-01-03  3:21 ` [PATCH 0/3] Add support for using libuser to chsh Cody Maloney
2013-01-03  3:21   ` [PATCH 1/3] chsh-chfn: Add flag for enabling/disabling libuser support Cody Maloney
2013-01-03  3:22   ` [PATCH 2/3] chsh: Move pam auth to its own function Cody Maloney
2013-01-03  3:22   ` [PATCH 3/3] chsh: Add libuser support Cody Maloney
2013-01-03 16:34     ` Miloslav Trmac
2013-01-07 11:51       ` Karel Zak
2013-01-08  6:15         ` Cody Maloney
2013-01-08  6:17         ` Cody Maloney
2013-01-08  6:18         ` Cody Maloney
2013-01-13  9:12   ` [PATCH 2/3] chsh: Move pam auth to its own function Cody Maloney
2013-01-13  9:12 ` [PATCH v2 1/4] chsh-chfn: Add flag for enabling/disabling libuser support Cody Maloney
2013-01-13  9:12 ` [PATCH v2 2/4] chsh-chfn: Move pam auth to its own function, factoring out common code Cody Maloney
2013-01-13  9:12 ` [PATCH v2 3/4] chsh: Add libuser support Cody Maloney
2013-01-14 18:16   ` Miloslav Trmac
2013-01-17  0:52     ` Cody Maloney
2013-01-28 22:01       ` Miloslav Trmac
2013-01-13  9:12 ` Cody Maloney [this message]
     [not found] ` <50F2FBBE.7000305@gmail.com>
2013-01-13 19:31   ` [PATCH v2 0/4] Add support for using libuser to chsh and chfn Cody Maloney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1358068345-773-6-git-send-email-cmaloney@theoreticalchaos.com \
    --to=cmaloney@theoreticalchaos.com \
    --cc=mitr@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox