return pass;
}
+#ifndef HAVE_EXPLICIT_BZERO
/* Ensure memory is set to value c without compiler optimization getting
* into way that could happen with memset(3). */
static int xmemset_s(void *v, size_t sz, const int c)
*p++ = c;
return 0;
}
+#endif
/* try to read password from gshadow */
static char *get_gshadow_pwd(const char *groupname)
if (pwd && *pwd && (xpwd = xgetpass(stdin, _("Password: ")))) {
char *cbuf = crypt(xpwd, pwd);
+#ifdef HAVE_EXPLICIT_BZERO
+ explicit_bzero(xpwd, strlen(xpwd));
+#else
xmemset_s(xpwd, strlen(xpwd), 0);
+#endif
free(xpwd);
if (!cbuf)
warn(_("crypt failed"));
return FALSE;
}
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
- fprintf(out, USAGE_HEADER);
+ FILE *out = stdout;
+ fputs(USAGE_HEADER, out);
fprintf(out, _(" %s <group>\n"), program_invocation_short_name);
fputs(USAGE_SEPARATOR, out);
fputs(_("Log in to a new group.\n"), out);
- fprintf(out, USAGE_OPTIONS);
- fprintf(out, USAGE_HELP);
- fprintf(out, USAGE_VERSION);
- fprintf(out, USAGE_MAN_TAIL("newgrp(1)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ fputs(USAGE_OPTIONS, out);
+ printf(USAGE_HELP_OPTIONS(16));
+ printf(USAGE_MAN_TAIL("newgrp(1)"));
+ exit(EXIT_SUCCESS);
}
int main(int argc, char *argv[])
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- atexit(close_stdout);
+ close_stdout_atexit();
while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
switch (ch) {
case 'V':
- printf(UTIL_LINUX_VERSION);
- return EXIT_SUCCESS;
+ print_version(EXIT_SUCCESS);
case 'h':
- usage(stdout);
+ usage();
default:
errtryhelp(EXIT_FAILURE);
}
shell = (pw_entry->pw_shell && *pw_entry->pw_shell ?
pw_entry->pw_shell : _PATH_BSHELL);
execl(shell, shell, (char *)0);
- warn(_("failed to execute %s"), shell);
- fflush(stderr);
-
- return EXIT_FAILURE;
+ errexec(shell);
}