char *des_crypt(const char *buf, const char *salt) { static char buff[14]; #ifndef CHARSET_EBCDIC return(des_fcrypt(buf,salt,buff)); #else char e_salt[2+1]; char e_buf[32+1]; /* replace 32 by 8 ? */ char *ret; /* Copy at most 2 chars of salt */ if ((e_salt[0] = salt[0]) != '\0') e_salt[1] = salt[1]; /* Copy at most 32 chars of password */ strncpy (e_buf, buf, sizeof(e_buf)); /* Make sure we have a delimiter */ e_salt[sizeof(e_salt)-1] = e_buf[sizeof(e_buf)-1] = '\0'; /* Convert the e_salt to ASCII, as that's what des_fcrypt works on */ ebcdic2ascii(e_salt, e_salt, sizeof e_salt); /* Convert the cleartext password to ASCII */ ebcdic2ascii(e_buf, e_buf, sizeof e_buf); /* Encrypt it (from/to ASCII) */ ret = des_fcrypt(e_buf,e_salt,buff); /* Convert the result back to EBCDIC */ ascii2ebcdic(ret, ret, strlen(ret)); return ret; #endif }
bool checkPermissions(const string& userId, const string& password, string&, const Current&) const { map<string, string>::const_iterator p = _passwords.find(userId); if(p == _passwords.end()) { return false; } if(p->second.size() != 13) // Crypt passwords are 13 characters long. { return false; } char buff[14]; string salt = p->second.substr(0, 2); #if OPENSSL_VERSION_NUMBER >= 0x0090700fL DES_fcrypt(password.c_str(), salt.c_str(), buff); #else des_fcrypt(password.c_str(), salt.c_str(), buff); #endif return p->second == buff; }