1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #include "Server.h" //#include <shadow.h> //#include <crypt.h> //#include <syslog.h> int IsLoading(int netfd){ if(send(netfd, "请输入用户名和密码", sizeof("请输入用户名和密码"), 0) <= 0){ printf("error recv loadmsg\n"); return -1; } char load[2][PATHLEN]; char *username = load[0]; if(recv(netfd, load, 2 * PATHLEN, 0) <= 0){ printf("error recv loadmsg\n"); return -1; }
struct spwd *info = getspnam(username); int i = strlen(info->sp_pwdp) - 1; for(; i >= 0; --i){ if(info->sp_pwdp[i] == '$'){ break; } } char *salt = (char *)malloc(i); strncpy(salt, info->sp_pwdp, i); salt[i] = '\0'; char *password = crypt(load[1], salt); printf("%s\n%s\n", salt, password); if(strcmp(info->sp_pwdp, password) == 0){ openlog("Server", LOG_PID | LOG_PERROR, LOG_USER); //syslog(LOG_ERR, "错误信息"); //syslog(LOG_WORNING, "错误信息"); return 0; }else{ return -1; } }
|