if ((pw = getpwnam(user)) == NULL) {
pw = getpwnam(user); if (pw == NULL) {
login(user, passwd, msg, msglen)    char *user;    char *passwd;    char **msg;    int *msglen;{    char *tty;#ifdef USE_PAM    struct pam_conv pam_conversation;    pam_handle_t *pamh;    int pam_error;    char *pass;    char *dev;/* * Fill the pam_conversion structure */    memset (&pam_conversation, '\0', sizeof (struct pam_conv));    pam_conversation.conv = &pam_conv;        pam_error = pam_start ("ppp", user, &pam_conversation, &pamh);    if (pam_error != PAM_SUCCESS) {        *msg = (char *) pam_strerror (pam_error);        return UPAP_AUTHNAK;    }/*         * Define the fields for the credintial validation */    (void) pam_set_item (pamh, PAM_AUTHTOK, passwd);    (void) pam_set_item (pamh, PAM_TTY, devnam);/* * Validate the user */    pam_error = pam_authenticate (pamh, PAM_SILENT);    if (pam_error == PAM_SUCCESS)        pam_error = pam_acct_mgmt (pamh, PAM_SILENT);        *msg = (char *) pam_strerror (pam_error);/* * Clean up the mess */    (void) pam_end (pamh, pam_error);       if (pam_error != PAM_SUCCESS)        return UPAP_AUTHNAK;/*   * Use the non-PAM methods directly */#else /* #ifdef USE_PAM */            struct passwd *pw;    char *epasswd;     #ifdef HAS_SHADOW    struct spwd *spwd;    struct spwd *getspnam();#endif           if ((pw = getpwnam(user)) == NULL) {        return (UPAP_AUTHNAK);    }       #ifdef HAS_SHADOW     if ((spwd = getspnam(user)) == NULL) {           pw->pw_passwd = "";    } else {        pw->pw_passwd = spwd->sp_pwdp;    }#endif        /*     * XXX If no passwd, let them login without one.     */    if (pw->pw_passwd == '\0') {        return (UPAP_AUTHACK);    }       #ifdef HAS_SHADOW     if (pw->pw_passwd) {        if (pw->pw_passwd[0] == '@') {            if (pw_auth (pw->pw_passwd+1, pw->pw_name, PW_PPP, NULL)) {                return (UPAP_AUTHNAK);            }        } else {            epasswd = pw_encrypt(passwd, pw->pw_passwd);            if (strcmp(epasswd, pw->pw_passwd)) {                return (UPAP_AUTHNAK);            }        }        /* check the age of the password entry */        if (spwd && (isexpired (pw, spwd) != 0)) {            return (UPAP_AUTHNAK);        }    }#else    epasswd = crypt(passwd, pw->pw_passwd);    if (strcmp(epasswd, pw->pw_passwd)) {        return (UPAP_AUTHNAK);    }#endif#endif /* #ifdef USE_PAM */       syslog(LOG_INFO, "user %s logged in", user);    /*     * Write a wtmp entry for this user.     */    tty = devnam;    if (strncmp(tty, "/dev/", 5) == 0)	tty += 5;    logwtmp(tty, user, remote_name);		/* Add wtmp login entry */    logged_in = TRUE;    return (UPAP_AUTHACK);}