2 * Copyright (C) 1998-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1999-02-02 14:51:39 adam
8 * Updated WIN32 code specific sections. Changed header.
10 * Revision 1.3 1998/06/25 19:16:32 adam
11 * Minor changes to Visual C++ project.
13 * Revision 1.2 1998/06/25 09:55:51 adam
14 * Minor changes - fixex headers.
40 struct passwd_entry *next;
44 struct passwd_entry *entries;
47 Passwd_db passwd_db_open (void)
49 struct passwd_db *p = xmalloc (sizeof(*p));
54 static int get_entry (const char **p, char *dst, int max)
57 while ((*p)[i] != ':' && (*p)[i])
70 int passwd_db_file (Passwd_db db, const char *fname)
74 f = fopen (fname, "r");
77 while (fgets (buf, sizeof(buf)-1, f))
79 struct passwd_entry *pe;
84 if ((p = strchr (buf, '\n')))
86 get_entry (&cp, name, 128);
87 get_entry (&cp, des, 128);
89 pe = xmalloc (sizeof(*pe));
90 pe->name = xstrdup (name);
91 pe->des = xstrdup (des);
92 pe->next = db->entries;
99 void passwd_db_close (Passwd_db db)
101 struct passwd_entry *pe = db->entries;
104 struct passwd_entry *pe_next = pe->next;
114 void passwd_db_show (Passwd_db db)
116 struct passwd_entry *pe;
117 for (pe = db->entries; pe; pe = pe->next)
118 logf (LOG_LOG,"%s:%s", pe->name, pe->des);
121 int passwd_db_auth (Passwd_db db, const char *user, const char *pass)
123 struct passwd_entry *pe;
128 for (pe = db->entries; pe; pe = pe->next)
129 if (user && !strcmp (user, pe->name))
134 if (strlen (pe->des) < 3)
138 memcpy (salt, pe->des, 2);
140 des_try = crypt (pass, salt);
141 if (strcmp (des_try, pe->des))
144 if (strcmp (pe->des, pass))