2 * Copyright (C) 1998, Index Data ApS
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1998-06-25 09:55:51 adam
8 * Minor changes - fixex headers.
31 struct passwd_entry *next;
35 struct passwd_entry *entries;
38 Passwd_db passwd_db_open (void)
40 struct passwd_db *p = xmalloc (sizeof(*p));
45 static int get_entry (const char **p, char *dst, int max)
48 while ((*p)[i] != ':' && (*p)[i])
61 int passwd_db_file (Passwd_db db, const char *fname)
65 f = fopen (fname, "r");
68 while (fgets (buf, sizeof(buf)-1, f))
70 struct passwd_entry *pe;
75 if ((p = strchr (buf, '\n')))
77 get_entry (&cp, name, 128);
78 get_entry (&cp, des, 128);
80 pe = xmalloc (sizeof(*pe));
81 pe->name = xstrdup (name);
82 pe->des = xstrdup (des);
83 pe->next = db->entries;
90 void passwd_db_close (Passwd_db db)
92 struct passwd_entry *pe = db->entries;
95 struct passwd_entry *pe_next = pe->next;
105 void passwd_db_show (Passwd_db db)
107 struct passwd_entry *pe;
108 for (pe = db->entries; pe; pe = pe->next)
109 logf (LOG_LOG,"%s:%s", pe->name, pe->des);
112 int passwd_db_auth (Passwd_db db, const char *user, const char *pass)
114 struct passwd_entry *pe;
119 for (pe = db->entries; pe; pe = pe->next)
120 if (user && !strcmp (user, pe->name))
125 if (strlen (pe->des) < 3)
129 memcpy (salt, pe->des, 2);
131 des_try = crypt (pass, salt);
132 if (strcmp (des_try, pe->des))
135 if (strcmp (pe->des, pass))