33#include <unordered_map>
41typedef std::unordered_map<std::string, std::string>
usermap_t;
60 unsigned int lineCount = 0;
62 while (fgets(buf,
sizeof(buf)-1, f) !=
nullptr) {
64 if ((buf[0] ==
'#') || (buf[0] ==
' ') || (buf[0] ==
'\t') ||
67 user = strtok(buf,
":\n\r");
68 if (user ==
nullptr) {
69 fprintf(stderr,
"ERROR: Missing user name at %s line %d\n",
passwdfile, lineCount);
72 passwd = strtok(
nullptr,
":\n\r");
73 if ((strlen(user) > 0) && passwd) {
86 char *user, *passwd, *p;
87 setbuf(stdout,
nullptr);
89 fprintf(stderr,
"Usage: ncsa_auth <passwordfile>\n");
92 if (stat(argv[1], &
sb) != 0) {
93 fprintf(stderr,
"FATAL: cannot stat %s\n", argv[1]);
97 if ((p = strchr(buf,
'\n')) !=
nullptr)
99 if (stat(argv[1], &
sb) == 0) {
105 if ((user = strtok(buf,
" ")) ==
nullptr) {
109 if ((passwd = strtok(
nullptr,
"")) ==
nullptr) {
115 const auto userpassIterator =
usermap.find(user);
116 if (userpassIterator ==
usermap.end()) {
120 std::string stored_pass = userpassIterator->second;
121 const char *salted = stored_pass.c_str();
123 char *crypted =
nullptr;
125 size_t passwordLength = strlen(passwd);
128 if (passwordLength > 1 && salted[0] ==
'$' &&
129 (crypted =
crypt(passwd, salted)) && stored_pass == crypted) {
134 if (passwordLength <= 8 && (crypted =
crypt(passwd, salted)) && stored_pass == crypted) {
138 if (passwordLength > 8 && (crypted =
crypt(passwd, salted)) && stored_pass == crypted) {
140 SEND_ERR(
"Password too long. Only 8 characters accepted.");
145 if ( (crypted =
crypt_md5(passwd, salted)) && stored_pass == crypted) {
149 if ( (crypted =
md5sum(passwd)) && stored_pass == crypted) {
#define HELPER_INPUT_BUFFER
int main(int argc, char **argv)
static void read_passwd_file(const char *passwdfile)
std::unordered_map< std::string, std::string > usermap_t
char * md5sum(const char *s)
char * crypt_md5(const char *pw, const char *salt)
char * crypt(const char *wort, const char *salt)
void rfc1738_unescape(char *url)
static time_t change_time
const char * xstrerr(int error)