18 struct passwd_entry *next;
22 struct passwd_entry *entries;
25 Passwd_db passwd_db_open (void)
27 struct passwd_db *p = xmalloc (sizeof(*p));
32 static int get_entry (const char **p, char *dst, int max)
35 while ((*p)[i] != ':' && (*p)[i])
48 int passwd_db_file (Passwd_db db, const char *fname)
52 f = fopen (fname, "r");
55 while (fgets (buf, sizeof(buf)-1, f))
57 struct passwd_entry *pe;
62 if ((p = strchr (buf, '\n')))
64 get_entry (&cp, name, 128);
65 get_entry (&cp, des, 128);
67 pe = xmalloc (sizeof(*pe));
68 pe->name = xstrdup (name);
69 pe->des = xstrdup (des);
70 pe->next = db->entries;
77 void passwd_db_close (Passwd_db db)
79 struct passwd_entry *pe = db->entries;
82 struct passwd_entry *pe_next = pe->next;
92 void passwd_db_show (Passwd_db db)
94 struct passwd_entry *pe;
95 for (pe = db->entries; pe; pe = pe->next)
96 logf (LOG_LOG,"%s:%s", pe->name, pe->des);
99 int passwd_db_auth (Passwd_db db, const char *user, const char *pass)
101 struct passwd_entry *pe;
106 for (pe = db->entries; pe; pe = pe->next)
107 if (user && !strcmp (user, pe->name))
112 if (strlen (pe->des) < 3)
116 memcpy (salt, pe->des, 2);
118 des_try = crypt (pass, salt);
119 if (strcmp (des_try, pe->des))
122 if (strcmp (pe->des, pass))