static void password_command(ostream &out, istream &in) { char username[200] ; char oldpwd[200] ; char newpwd[200] ; out << "User name: " << flush ; in.ignore(1000,'\n') ; in.getline(username,sizeof(username)) ; out << "Old password: "******"New password: "******"Unknown username!" ; return ; } if (set_user_password(oldpwd,newpwd,userinfo)) { cout << "Successfully set password." << endl ; if (!store_userinfo()) cout << "....but error updating user information file!" << endl ; } else cout << "Password update failed!" << endl ; }
/* * Name: auth_check_userpass * * Description: Checks user's password. Returns 0 when sucessful and password * is ok, else returns nonzero; As one-way function is used RSA's MD5 w/ * BASE64 encoding. #ifdef EMBED * On embedded environments we use crypt(), instead of MD5. #endif */ int auth_check_userpass(char *user,char *pass,FILE *authfile) { #ifdef LDAP_HACK /* Yeah, code before declarations will fail on older compilers... */ switch (ldap_auth(user, pass)) { case -1: ldap_succ = 0; return 1; case 0: ldap_succ = strcmp(user, "root")?0:1; break; case 1: ldap_succ = 1; if (start_user_update(0) == 0) done_user_update(set_user_password(user, pass, 0)==0?1:0); return 0; } #endif #ifdef SHADOW_AUTH struct spwd *sp; sp = getspnam(user); if (!sp) return 2; if (!strcmp(crypt(pass, sp->sp_pwdp), sp->sp_pwdp)) return 0; #else #ifndef EMBED char temps[0x100],*pwd; struct MD5Context mc; unsigned char final[16]; char encoded_passwd[0x40]; /* Encode password ('pass') using one-way function and then use base64 encoding. */ MD5Init(&mc); MD5Update(&mc, pass, strlen(pass)); MD5Final(final, &mc); strcpy(encoded_passwd,"$1$"); base64encode(final, encoded_passwd+3, 16); DBG(printf("auth_check_userpass(%s,%s,...);\n",user,pass);)
static gpointer thread_create_user (gpointer data) { struct PasswdHandler *handler = (struct PasswdHandler *) data; if (!add_user (handler->username)) { g_warning ("create user:add user failed\n"); emit_progress ("user", "terminate"); return NULL; } if (!set_user_home (handler->username)) { g_warning ("create user:set user home failed\n"); emit_progress ("user", "terminate"); return NULL; } if (!set_group (handler->username)) { g_warning ("create user:set group failed\n"); emit_progress ("user", "terminate"); return NULL; } if (!write_hostname (handler->hostname)) { g_warning ("create user:write hostname failed\n"); emit_progress ("user", "terminate"); return NULL; } if (!set_user_password (handler)) { g_warning ("create user:set user password failed\n"); emit_progress ("user", "terminate"); return NULL; } emit_progress ("user", "finish"); return NULL; }