2 * Copyright (C) 1998-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1999-05-26 07:49:14 adam
10 * Revision 1.4 1999/02/02 14:51:39 adam
11 * Updated WIN32 code specific sections. Changed header.
13 * Revision 1.3 1998/06/25 19:16:32 adam
14 * Minor changes to Visual C++ project.
16 * Revision 1.2 1998/06/25 09:55:51 adam
17 * Minor changes - fixex headers.
43 struct passwd_entry *next;
47 struct passwd_entry *entries;
50 Passwd_db passwd_db_open (void)
52 struct passwd_db *p = (struct passwd_db *) xmalloc (sizeof(*p));
57 static int get_entry (const char **p, char *dst, int max)
60 while ((*p)[i] != ':' && (*p)[i])
73 int passwd_db_file (Passwd_db db, const char *fname)
77 f = fopen (fname, "r");
80 while (fgets (buf, sizeof(buf)-1, f))
82 struct passwd_entry *pe;
87 if ((p = strchr (buf, '\n')))
89 get_entry (&cp, name, 128);
90 get_entry (&cp, des, 128);
92 pe = (struct passwd_entry *) xmalloc (sizeof(*pe));
93 pe->name = xstrdup (name);
94 pe->des = xstrdup (des);
95 pe->next = db->entries;
102 void passwd_db_close (Passwd_db db)
104 struct passwd_entry *pe = db->entries;
107 struct passwd_entry *pe_next = pe->next;
117 void passwd_db_show (Passwd_db db)
119 struct passwd_entry *pe;
120 for (pe = db->entries; pe; pe = pe->next)
121 logf (LOG_LOG,"%s:%s", pe->name, pe->des);
124 int passwd_db_auth (Passwd_db db, const char *user, const char *pass)
126 struct passwd_entry *pe;
131 for (pe = db->entries; pe; pe = pe->next)
132 if (user && !strcmp (user, pe->name))
137 if (strlen (pe->des) < 3)
141 memcpy (salt, pe->des, 2);
143 des_try = crypt (pass, salt);
144 if (strcmp (des_try, pe->des))
147 if (strcmp (pe->des, pass))