2 * Copyright (C) 1998, Index Data ApS
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1998-06-25 19:16:32 adam
8 * Minor changes to Visual C++ project.
10 * Revision 1.2 1998/06/25 09:55:51 adam
11 * Minor changes - fixex headers.
37 struct passwd_entry *next;
41 struct passwd_entry *entries;
44 Passwd_db passwd_db_open (void)
46 struct passwd_db *p = xmalloc (sizeof(*p));
51 static int get_entry (const char **p, char *dst, int max)
54 while ((*p)[i] != ':' && (*p)[i])
67 int passwd_db_file (Passwd_db db, const char *fname)
71 f = fopen (fname, "r");
74 while (fgets (buf, sizeof(buf)-1, f))
76 struct passwd_entry *pe;
81 if ((p = strchr (buf, '\n')))
83 get_entry (&cp, name, 128);
84 get_entry (&cp, des, 128);
86 pe = xmalloc (sizeof(*pe));
87 pe->name = xstrdup (name);
88 pe->des = xstrdup (des);
89 pe->next = db->entries;
96 void passwd_db_close (Passwd_db db)
98 struct passwd_entry *pe = db->entries;
101 struct passwd_entry *pe_next = pe->next;
111 void passwd_db_show (Passwd_db db)
113 struct passwd_entry *pe;
114 for (pe = db->entries; pe; pe = pe->next)
115 logf (LOG_LOG,"%s:%s", pe->name, pe->des);
118 int passwd_db_auth (Passwd_db db, const char *user, const char *pass)
120 struct passwd_entry *pe;
125 for (pe = db->entries; pe; pe = pe->next)
126 if (user && !strcmp (user, pe->name))
131 if (strlen (pe->des) < 3)
135 memcpy (salt, pe->des, 2);
137 des_try = crypt (pass, salt);
138 if (strcmp (des_try, pe->des))
141 if (strcmp (pe->des, pass))