struct passwd * parseUser(char *data) { char **tokens; int ntokens; if (data == NULL) return NULL; tokens = tokenize(data, ":"); ntokens = listLength(tokens); if (( _pwFileFormat && (ntokens != 10)) || (!_pwFileFormat && (ntokens != 7))) { freeList(tokens); return NULL; } free_pw(); _pw.pw_name = tokens[0]; _pw.pw_passwd = tokens[1]; _pw.pw_uid = atoi(tokens[2]); free(tokens[2]); _pw.pw_gid = atoi(tokens[3]); free(tokens[3]); if (_pwFileFormat) { _pw.pw_class = tokens[4]; _pw.pw_change = atoi(tokens[5]); free(tokens[5]); _pw.pw_expire = atoi(tokens[6]); free(tokens[6]); _pw.pw_gecos = tokens[7]; _pw.pw_dir = tokens[8]; _pw.pw_shell = tokens[9]; } else { _pw.pw_class = copyString(""); _pw.pw_change = 0; _pw.pw_expire = 0; _pw.pw_gecos = tokens[4]; _pw.pw_dir = tokens[5]; _pw.pw_shell = tokens[6]; } free(tokens); return &_pw; }
/** char* get_passwd(char* user_id) ユーザ user_id のパスワードを得る.@n パスワードの検索順は /etc/passwd, /etc/shadow, NIS @param user_id ユーザ名 @return ユーザの暗号化(ハッシュ値化)されたパスワード @retval NULL 失敗 */ char* get_passwd(char* user_id) { struct passwd* pw; struct spwd* sp; char* pass; pass = (char*)malloc(LPASS+1); if (pass==NULL) return NULL; memset(pass, 0, LPASS+1); // for /etc/passwd pw = getpwnam((const char*)user_id); if (pw==NULL) { free(pass); return NULL; } strncpy(pass, pw->pw_passwd, LPASS); if (strcmp(pass, "*") && strcmp(pass, "x") && strcmp(pass, "!")) return pass; #ifdef HAVE_GETSPNAM // for /etc/shadow sp = getspnam((const char*)user_id); if (sp!=NULL) { strncpy(pass, sp->sp_pwdp, LPASS); return pass; } #endif #ifdef HAVE_RPCSVC_YPCLNT_H // for NIS pw = getnisnam(user_id); if (pw!=NULL) { strncpy(pass, pw->pw_passwd, LPASS); free_pw(pw); return pass; } #endif return NULL; }