char *Prog;
static const char *hostname = "";
-static char username[32];
+static char *username = NULL;
static int reason = PW_LOGIN;
static struct passwd pwent;
int arg;
int flag;
- username[0] = '\0';
-
/*
* Check the flags for proper form. Every argument starting with
* "-" must be exactly two characters long. This closes all the
}
fflg = true;
if (optarg) {
- STRFCPY (username, optarg);
+ username = xstrdup (optarg);
}
break;
case 'h':
* Get the user name.
*/
if (optind < argc) {
- if (rflg || (fflg && ('\0' != username[0]))) {
+ if (rflg || (fflg && (NULL != username))) {
usage ();
}
- STRFCPY (username, argv[optind]);
+ username = xstrdup (argv[optind]);
strzero (argv[optind]);
++optind;
}
reason = PW_RLOGIN;
}
#ifdef RLOGIN
- if ( rflg
- && do_rlogin (hostname, username, sizeof username,
- term, sizeof term)) {
- preauth_flag = true;
+ if (rflg) {
+ username = malloc (32 * sizeof char);
+ if (do_rlogin (hostname, username, 32, term, sizeof term)) {
+ preauth_flag = true;
+ } else {
+ free (username);
+ username = NULL;
+ }
}
#endif
#else /* ! USE_PAM */
while (true) { /* repeatedly get login/password pairs */
failed = false; /* haven't failed authentication yet */
- if ('\0' == username[0]) { /* need to get a login id */
+ if (NULL == username) { /* need to get a login id */
if (subroot) {
closelog ();
exit (1);
}
preauth_flag = false;
- login_prompt (_("\n%s login: "), username,
- sizeof username);
- continue;
+ username = malloc (32);
+ login_prompt (_("\n%s login: "), username, 32);
+
+ if ('\0' == username) {
+ /* Prompt for a new login */
+ free (username);
+ username = NULL;
+ continue;
+ }
}
pwd = xgetpwnam (username);
failent.ut_type = USER_PROCESS;
failtmp (&failent);
}
- memzero (username, sizeof username);
+ free (username);
+ username = NULL;
retries--;
if (retries <= 0) {