115: void readPasswords() { 116: struct passwd *pwd; 117: struct spwd *spwd = NULL; 118: if (!(pwd = getpwnam(userName))) { 119: writeMsg("no entry for %s in /etc/passwd\n",userName); 120: exit(3); 121: } else { 122: encryptedPassword = pwd->pw_passwd; 123: userId = pwd->pw_uid; 124: groupId = pwd->pw_gid; 125: } 126: endpwent(); 127: 128: if (strcmp(encryptedPassword,"x") == 0 || strcmp(encryptedPassword,"*") == 0) { 129: if (!(spwd = getspnam(userName))) { 130: writeMsg("no entry for %s in /etc/shadow\n",userName); 131: exit(3); 132: } else 133: encryptedPassword = spwd->sp_pwdp; 134: endspent(); 135: } 136: writeMsg("encrypted password: %s\n",encryptedPassword); 137: writeMsg("numeric user-id: %lu\n",userId); 138: writeMsg("numeric group-id: %lu\n",groupId); 139: } 140: 143: int checkPassword() { 144: int rc; 145: 146: if (*clearTextPassword == '\0' && ( 147: encryptedPassword == (char *) 0 || *encryptedPassword == '\0')) 148: return OK; 149: else if (*clearTextPassword != '\0' && ( 150: encryptedPassword == (char *) 0 || *encryptedPassword == '\0')) { 151: bzero(clearTextPassword,strlen(clearTextPassword)); 152: return FAILED; 153: } 154: 155: rc = strcmp(encryptPassword(),encryptedPassword); 156: bzero(clearTextPassword,strlen(clearTextPassword)); 157: if (rc == 0) 158: return OK; 159: else 160: return FAILED; 161: } 162: 165: char *encryptPassword() { 166: static char cipher[128]; 167: char *p; 168: const char *salt = encryptedPassword; 169: p = crypt(clearTextPassword,salt); 170: if (strlen(p) > sizeof(cipher)-1) 171: p[sizeof(cipher)-1] = 0; 172: strcpy(cipher,p); 173: writeMsg("encrypted password: %s\n",cipher); 174: return cipher; 175: }