2 * Copyright (C) 1998-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1999-11-30 13:48:04 adam
8 * Improved installation. Updated for inclusion of YAZ header files.
10 * Revision 1.5 1999/05/26 07:49:14 adam
13 * Revision 1.4 1999/02/02 14:51:39 adam
14 * Updated WIN32 code specific sections. Changed header.
16 * Revision 1.3 1998/06/25 19:16:32 adam
17 * Minor changes to Visual C++ project.
19 * Revision 1.2 1998/06/25 09:55:51 adam
20 * Minor changes - fixex headers.
39 #include <yaz/xmalloc.h>
46 struct passwd_entry *next;
50 struct passwd_entry *entries;
53 Passwd_db passwd_db_open (void)
55 struct passwd_db *p = (struct passwd_db *) xmalloc (sizeof(*p));
60 static int get_entry (const char **p, char *dst, int max)
63 while ((*p)[i] != ':' && (*p)[i])
76 int passwd_db_file (Passwd_db db, const char *fname)
80 f = fopen (fname, "r");
83 while (fgets (buf, sizeof(buf)-1, f))
85 struct passwd_entry *pe;
90 if ((p = strchr (buf, '\n')))
92 get_entry (&cp, name, 128);
93 get_entry (&cp, des, 128);
95 pe = (struct passwd_entry *) xmalloc (sizeof(*pe));
96 pe->name = xstrdup (name);
97 pe->des = xstrdup (des);
98 pe->next = db->entries;
105 void passwd_db_close (Passwd_db db)
107 struct passwd_entry *pe = db->entries;
110 struct passwd_entry *pe_next = pe->next;
120 void passwd_db_show (Passwd_db db)
122 struct passwd_entry *pe;
123 for (pe = db->entries; pe; pe = pe->next)
124 logf (LOG_LOG,"%s:%s", pe->name, pe->des);
127 int passwd_db_auth (Passwd_db db, const char *user, const char *pass)
129 struct passwd_entry *pe;
134 for (pe = db->entries; pe; pe = pe->next)
135 if (user && !strcmp (user, pe->name))
140 if (strlen (pe->des) < 3)
144 memcpy (salt, pe->des, 2);
146 des_try = crypt (pass, salt);
147 if (strcmp (des_try, pe->des))
150 if (strcmp (pe->des, pass))