diff options
author | Marek Polacek | 2010-11-30 22:53:31 +0100 |
---|---|---|
committer | Karel Zak | 2010-12-02 17:15:51 +0100 |
commit | 1fa30199c69ac25bbfb72df661ee17a13c757539 (patch) | |
tree | ba6ccc69d8645cc81e08c84d0c36db8dffe61d71 /login-utils | |
parent | README: fix typo (diff) | |
download | kernel-qcow2-util-linux-1fa30199c69ac25bbfb72df661ee17a13c757539.tar.gz kernel-qcow2-util-linux-1fa30199c69ac25bbfb72df661ee17a13c757539.tar.xz kernel-qcow2-util-linux-1fa30199c69ac25bbfb72df661ee17a13c757539.zip |
newgrp: Use err() and EXIT_*
Use err() or errx() where appropriate. Also use EXIT_* macros instead
of 0/1. All error messages shall start with lowercase.
Signed-off-by: Marek Polacek <mmpolacek@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils')
-rw-r--r-- | login-utils/newgrp.c | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/login-utils/newgrp.c b/login-utils/newgrp.c index 976a04939..6323af198 100644 --- a/login-utils/newgrp.c +++ b/login-utils/newgrp.c @@ -14,6 +14,7 @@ #include <stdio.h> #include <stdlib.h> #include <errno.h> +#include <err.h> #include "c.h" #include "pathnames.h" @@ -54,7 +55,7 @@ get_gshadow_pwd(char *groupname) } static int -allow_setgid(struct passwd *pe, struct group *ge) +allow_setgid(struct passwd *pe, struct group *ge) { char **look; int notfound = 1; @@ -84,7 +85,7 @@ allow_setgid(struct passwd *pe, struct group *ge) return FALSE; /* default to denial */ } -int +int main(int argc, char *argv[]) { struct passwd *pw_entry; @@ -95,47 +96,37 @@ main(int argc, char *argv[]) bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - if (!(pw_entry = getpwuid(getuid()))) { - perror(_("newgrp: Who are you?")); - exit(1); - } + if (!(pw_entry = getpwuid(getuid()))) + err(EXIT_FAILURE, _("who are you?")); shell = (pw_entry->pw_shell[0] ? pw_entry->pw_shell : _PATH_BSHELL); if (argc < 2) { - if(setgid(pw_entry->pw_gid) < 0) { - perror(_("newgrp: setgid")); - exit(1); - } + if(setgid(pw_entry->pw_gid) < 0) + err(EXIT_FAILURE, _("setgid failed")); } else { errno = 0; if (!(gr_entry = getgrnam(argv[1]))) { if (errno) - perror(_("newgrp: No such group.")); /* error */ + err(EXIT_FAILURE, _("no such group")); else - fprintf(stderr, "%s\n", _("newgrp: No such group.")); /* no group */ - exit(1); + errx(EXIT_FAILURE, _("no such group")); /* No group */ } else { - if(allow_setgid(pw_entry, gr_entry)) { - if(setgid(gr_entry->gr_gid) < 0) { - perror(_("newgrp: setgid")); - exit(1); - } - } else { - puts(_("newgrp: Permission denied")); - exit(1); - } + if (allow_setgid(pw_entry, gr_entry)) { + if (setgid(gr_entry->gr_gid) < 0) + err(EXIT_FAILURE, _("setgid failed")); + } else + errx(EXIT_FAILURE, _("permission denied")); } } - if(setuid(getuid()) < 0) { - perror(_("newgrp: setuid")); - exit(1); - } + if (setuid(getuid()) < 0) + err(EXIT_FAILURE, _("setuid failed")); fflush(stdout); fflush(stderr); execl(shell,shell,(char*)0); - perror(_("No shell")); + warn(_("exec %s failed"), shell); fflush(stderr); - exit(1); + + return EXIT_FAILURE; } |