1 /* $Id: passwddb.c,v 1.7 2002-08-02 19:26:57 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
40 #include <yaz/xmalloc.h>
47 struct passwd_entry *next;
51 struct passwd_entry *entries;
54 Passwd_db passwd_db_open (void)
56 struct passwd_db *p = (struct passwd_db *) xmalloc (sizeof(*p));
61 static int get_entry (const char **p, char *dst, int max)
64 while ((*p)[i] != ':' && (*p)[i])
77 int passwd_db_file (Passwd_db db, const char *fname)
81 f = fopen (fname, "r");
84 while (fgets (buf, sizeof(buf)-1, f))
86 struct passwd_entry *pe;
91 if ((p = strchr (buf, '\n')))
93 get_entry (&cp, name, 128);
94 get_entry (&cp, des, 128);
96 pe = (struct passwd_entry *) xmalloc (sizeof(*pe));
97 pe->name = xstrdup (name);
98 pe->des = xstrdup (des);
99 pe->next = db->entries;
106 void passwd_db_close (Passwd_db db)
108 struct passwd_entry *pe = db->entries;
111 struct passwd_entry *pe_next = pe->next;
121 void passwd_db_show (Passwd_db db)
123 struct passwd_entry *pe;
124 for (pe = db->entries; pe; pe = pe->next)
125 logf (LOG_LOG,"%s:%s", pe->name, pe->des);
128 int passwd_db_auth (Passwd_db db, const char *user, const char *pass)
130 struct passwd_entry *pe;
135 for (pe = db->entries; pe; pe = pe->next)
136 if (user && !strcmp (user, pe->name))
141 if (strlen (pe->des) < 3)
145 memcpy (salt, pe->des, 2);
147 des_try = crypt (pass, salt);
148 if (strcmp (des_try, pe->des))
151 if (strcmp (pe->des, pass))