-/* $Id: passwddb.h,v 1.4 2002-08-02 19:26:55 adam Exp $
+/* $Id: passwddb.h,v 1.4.2.1 2005-05-30 13:24:53 adam Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
Passwd_db passwd_db_open (void);
int passwd_db_auth (Passwd_db db, const char *user, const char *pass);
-int passwd_db_file (Passwd_db db, const char *fname);
+int passwd_db_file_plain(Passwd_db db, const char *fname);
+int passwd_db_file_crypt(Passwd_db db, const char *fname);
void passwd_db_close (Passwd_db db);
void passwd_db_show (Passwd_db db);
-/* $Id: zebraapi.c,v 1.120.2.7 2005-05-18 12:20:34 adam Exp $
+/* $Id: zebraapi.c,v 1.120.2.8 2005-05-30 13:24:53 adam Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
if ((res = res_open (configName, def_res, over_res)))
{
+ const char *passwd_plain = 0;
+ const char *passwd_encrypt = 0;
ZebraService zh = xmalloc (sizeof(*zh));
yaz_log (LOG_DEBUG, "Read resources `%s'", configName);
zebra_chdir (zh);
zebra_mutex_cond_init (&zh->session_lock);
- if (!res_get (zh->global_res, "passwd"))
+ passwd_plain = res_get (zh->global_res, "passwd");
+ passwd_encrypt = res_get (zh->global_res, "passwd.c");
+
+ if (!passwd_plain && !passwd_encrypt)
zh->passwd_db = NULL;
else
{
- zh->passwd_db = passwd_db_open ();
+ zh->passwd_db = passwd_db_open();
if (!zh->passwd_db)
logf (LOG_WARN|LOG_ERRNO, "passwd_db_open failed");
else
- passwd_db_file (zh->passwd_db,
- res_get (zh->global_res, "passwd"));
+ {
+ if (passwd_plain)
+ if (passwd_db_file_plain(zh->passwd_db, passwd_plain))
+ {
+ logf(LOG_WARN,
+ "Failed to read passwords %s (or unsupported)",
+ passwd_plain);
+ }
+ if (passwd_encrypt)
+ {
+ if (passwd_db_file_crypt(zh->passwd_db, passwd_encrypt))
+ {
+ logf(LOG_WARN,
+ "Failed to read encrypted pwds %s "
+ "(or unsupported)", passwd_encrypt);
+ }
+ }
+
+ }
}
zh->path_root = res_get (zh->global_res, "root");
return zh;
-/* $Id: passtest.c,v 1.4 2002-08-02 19:26:57 adam Exp $
+/* $Id: passtest.c,v 1.4.2.1 2005-05-30 13:24:53 adam Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
int main (int argc, char **argv)
{
- Passwd_db db;
-
- db = passwd_db_open();
-
- passwd_db_file (db, "/etc/passwd");
- passwd_db_auth (db, "adam", "xtx9Y=");
- passwd_db_close (db);
- return 0;
+ Passwd_db db;
+
+ db = passwd_db_open();
+
+ passwd_db_file_plain(db, "/etc/passwd");
+ passwd_db_auth(db, "adam", "xtx9Y=");
+ passwd_db_close(db);
+ return 0;
}
-/* $Id: passwddb.c,v 1.7.2.1 2005-05-12 08:02:47 adam Exp $
+/* $Id: passwddb.c,v 1.7.2.2 2005-05-30 13:24:54 adam Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
#include <passwddb.h>
struct passwd_entry {
- char *name;
- char *des;
- struct passwd_entry *next;
+ char *name;
+ char *des;
+ int encrypt_flag;
+ struct passwd_entry *next;
};
struct passwd_db {
return i;
}
-int passwd_db_file (Passwd_db db, const char *fname)
+static int passwd_db_file_int(Passwd_db db, const char *fname,
+ int encrypt_flag)
{
- FILE *f;
- char buf[1024];
- f = fopen (fname, "r");
- if (!f)
- return -1;
- while (fgets (buf, sizeof(buf)-1, f))
- {
- struct passwd_entry *pe;
- char name[128];
- char des[128];
- char *p;
- const char *cp = buf;
- if ((p = strchr (buf, '\n')))
- *p = '\0';
- get_entry (&cp, name, 128);
- get_entry (&cp, des, 128);
-
- pe = (struct passwd_entry *) xmalloc (sizeof(*pe));
- pe->name = xstrdup (name);
- pe->des = xstrdup (des);
- pe->next = db->entries;
- db->entries = pe;
- }
- fclose (f);
- return 0;
+ FILE *f;
+ char buf[1024];
+ f = fopen (fname, "r");
+ if (!f)
+ return -1;
+ while (fgets (buf, sizeof(buf)-1, f))
+ {
+ struct passwd_entry *pe;
+ char name[128];
+ char des[128];
+ char *p;
+ const char *cp = buf;
+ if ((p = strchr (buf, '\n')))
+ *p = '\0';
+ get_entry (&cp, name, 128);
+ get_entry (&cp, des, 128);
+
+ pe = (struct passwd_entry *) xmalloc (sizeof(*pe));
+ pe->name = xstrdup (name);
+ pe->encrypt_flag = encrypt_flag;
+ pe->des = xstrdup (des);
+ pe->next = db->entries;
+ db->entries = pe;
+ }
+ fclose (f);
+ return 0;
}
+
void passwd_db_close (Passwd_db db)
{
- struct passwd_entry *pe = db->entries;
- while (pe)
- {
- struct passwd_entry *pe_next = pe->next;
+ struct passwd_entry *pe = db->entries;
+ while (pe)
+ {
+ struct passwd_entry *pe_next = pe->next;
- xfree (pe->name);
- xfree (pe->des);
- xfree (pe);
- pe = pe_next;
- }
- xfree (db);
+ xfree (pe->name);
+ xfree (pe->des);
+ xfree (pe);
+ pe = pe_next;
+ }
+ xfree (db);
}
void passwd_db_show (Passwd_db db)
{
- struct passwd_entry *pe;
- for (pe = db->entries; pe; pe = pe->next)
- logf (LOG_LOG,"%s:%s", pe->name, pe->des);
+ struct passwd_entry *pe;
+ for (pe = db->entries; pe; pe = pe->next)
+ logf (LOG_LOG,"%s:%s", pe->name, pe->des);
}
int passwd_db_auth (Passwd_db db, const char *user, const char *pass)
{
- struct passwd_entry *pe;
+ struct passwd_entry *pe;
+ for (pe = db->entries; pe; pe = pe->next)
+ if (user && !strcmp (user, pe->name))
+ break;
+ if (!pe)
+ return -1;
+ if (pe->encrypt_flag)
+ {
#if HAVE_CRYPT_H
char salt[3];
const char *des_try;
-#endif
- for (pe = db->entries; pe; pe = pe->next)
- if (user && !strcmp (user, pe->name))
- break;
- if (!pe)
- return -1;
-#if HAVE_CRYPT_H
if (strlen (pe->des) < 3)
- return -3;
+ return -3;
if (!pass)
return -2;
memcpy (salt, pe->des, 2);
salt[2] = '\0';
des_try = crypt (pass, salt);
if (strcmp (des_try, pe->des))
- return -2;
+ return -2;
#else
+ return -2;
+#endif
+ }
+ else
+ {
if (strcmp (pe->des, pass))
- return -2;
+ return -2;
+ }
+ return 0;
+}
+
+int passwd_db_file_crypt(Passwd_db db, const char *fname)
+{
+#if HAVE_CRYPT_H
+ return passwd_db_file_int(db, fname, 1);
+#else
+ return -1;
#endif
- return 0;
+}
+
+int passwd_db_file_plain(Passwd_db db, const char *fname)
+{
+ return passwd_db_file_int(db, fname, 0);
}