char* crypt_pass(const char* pw, const char* mech) { crypt_mechs_t* crypt_mech; char* salt, *untagged, *tagged; assert(NULL != pw); assert(NULL != mech); Debug((DEBUG_DEBUG, "pw = %s\n", pw)); Debug((DEBUG_DEBUG, "mech = %s\n", mech)); if (NULL == (crypt_mech = hunt_mech(mech))) { printf("Unable to find mechanism %s\n", mech); return NULL; } salt = make_salt(default_salts); untagged = (char *)CryptFunc(crypt_mech->mech)(pw, salt); tagged = (char *)MyMalloc(strlen(untagged)+CryptTokSize(crypt_mech->mech)+1); memset(tagged, 0, strlen(untagged)+CryptTokSize(crypt_mech->mech)+1); strncpy(tagged, CryptTok(crypt_mech->mech), CryptTokSize(crypt_mech->mech)); strncpy(tagged+CryptTokSize(crypt_mech->mech), untagged, strlen(untagged)); return tagged; }
/* ** mo_test ** parv[0] = sender prefix ** parv[1] = parameter */ static void mo_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) { int is_md5 = 0; if (parc == 3) { if (!irccmp(parv[2], "MD5")) { is_md5 = 1; } else if (!irccmp(parv[2], "DES")) { /* Not really needed, but we may want to have a default encryption * setting somewhere down the road */ is_md5 = 0; } else { sendto_one(source_p, ":%s NOTICE %s :MKPASSWD syntax error: MKPASSWD pass [DES|MD5]", me.name, parv[0]); return; } } if (parc == 1) sendto_one(source_p, form_str(source_p,ERR_NEEDMOREPARAMS), me.name, parv[0], "MKPASSWD"); else sendto_one(source_p, ":%s NOTICE %s :Encryption for [%s]: %s", me.name, parv[0], parv[1], crypt(parv[1], is_md5 ? make_md5_salt() : make_salt())); }
static int m_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { static time_t last_used = 0; int is_md5 = 0; if((last_used + ConfigFileEntry.pace_wait) > CurrentTime) { /* safe enough to give this on a local connect only */ sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, parv[0]); return 0; } else { last_used = CurrentTime; } if(parc == 3) { if(!irccmp(parv[2], "MD5")) { is_md5 = 1; } else if(!irccmp(parv[2], "DES")) { /* Not really needed, but we may want to have a default encryption * setting somewhere down the road */ is_md5 = 0; } else { sendto_one(source_p, ":%s NOTICE %s :MKPASSWD syntax error: MKPASSWD pass [DES|MD5]", me.name, parv[0]); return 0; } } if(parc == 1) sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "MKPASSWD"); else sendto_one(source_p, ":%s NOTICE %s :Encryption for [%s]: %s", me.name, parv[0], parv[1], crypt(parv[1], is_md5 ? make_md5_salt() : make_salt())); return 0; }
int crypt_password(char *password, char *crypted, int max) { char salt[24], *pw; make_salt(salt); pthread_mutex_lock(&crypt_lock); if ((pw = crypt(password, salt)) == NULL) { pthread_mutex_unlock(&crypt_lock); *crypted = 0; return -1; } cstrcpy(crypted, pw, max); pthread_mutex_unlock(&crypt_lock); return 0; }