static bool pass_set(struct userrec *u, struct user_entry *e, void *buf) { char *newpass = NULL; register char *pass = (char *) buf; if (e->u.extra) free(e->u.extra); if (!pass || !pass[0] || (pass[0] == '-')) e->u.extra = NULL; else { unsigned char *p = (unsigned char *) pass; if (u->bot || (pass[0] == '+')) newpass = strdup(pass); else { while (*p) { if ((*p <= 32) || (*p == 127)) *p = '?'; p++; } newpass = salted_sha1(pass); } e->u.extra = strdup(newpass); } if (!noshare) shareout("c %s %s %s\n", e->type->name, u->handle, newpass ? newpass : ""); if (newpass) free(newpass); /* clear old records */ noshare = 1; set_user(&USERENTRY_PASS1, u, NULL); noshare = 0; return 1; }
int salted_sha1cmp(const char *salted_hash, const char *string) { char* cmp = salted_sha1(string, &salted_hash[1]); //Pass in the salt from the given hash int n = strcmp(salted_hash, cmp); free(cmp); return n; }