1 /* $Id: passwddb.c,v 1.11 2005-05-12 10:10:32 adam Exp $
2 Copyright (C) 1995-2005
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
36 #include <yaz/xmalloc.h>
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 yaz_log (YLOG_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))