db-passwd-file.c revision 0dfadf47a8d705a7425575fb490da434edc6b978
/* Copyright (C) 2002-2003 Timo Sirainen */
#include "common.h"
#if defined (USERDB_PASSWD_FILE) || defined(PASSDB_PASSWD_FILE)
#include "userdb.h"
#include "db-passwd-file.h"
#include "buffer.h"
#include "istream.h"
#include "hash.h"
#include "str.h"
#include "var-expand.h"
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
static struct db_passwd_file *passwd_files;
{
/* args = uid, gid, user info, home dir, shell, extra_fields */
struct passwd_user *pu;
const char *extra_fields = NULL;
char *user;
i_error("passwd-file %s: User %s exists more than once",
return;
}
/* password[type] - we're being libpam-pwdfile compatible
here. it uses 13 = DES and 34 = MD5. For backwards
comaptibility with ourself, we have also 56 = Digest-MD5. */
if (num == 34) {
} else if (num == 56) {
i_error("passwd-file %s: User %s "
"has invalid password",
return;
}
} else {
}
} else {
}
;
args++;
} else {
i_error("passwd-file %s: User %s has invalid UID '%s'",
return;
}
args++;
}
i_error("passwd-file %s: User %s is missing "
}
args++;
else {
i_error("passwd-file %s: User %s has invalid GID '%s'",
return;
}
args++;
}
/* user info */
args++;
/* home */
args++;
}
/* shell */
args++;
/* old format, this field is empty and next field may
contain MAIL */
args++;
t_strconcat("userdb_mail=",
}
/* new format, contains a space separated list of
extra fields */
}
if (extra_fields != NULL) {
pu->extra_fields =
}
}
static struct passwd_file *
{
struct passwd_file *pw;
return pw;
}
{
const char *const *args;
const char *line;
int fd;
if (fd == -1) {
return FALSE;
}
return FALSE;
}
continue; /* no username or comment */
t_push();
/* at least username+password */
} else {
/* only username */
}
t_pop();
}
i_info("passwd-file %s: Read %u users",
}
return TRUE;
}
{
}
}
}
}
{
}
{
/* with variables don't give hard errors, or errors about
nonexisting files */
return FALSE;
}
return passwd_file_open(pw);
}
return TRUE;
}
{
struct db_passwd_file *f;
return f;
}
return NULL;
}
struct db_passwd_file *
{
struct db_passwd_file *db;
const char *p;
return db;
}
for (p = path; *p != '\0'; p++) {
if (*p == '%' && p[1] != '\0') {
p++;
if (*p == 'd') {
/* drop domains out only if %d is given
without modifiers */
}
if (var_get_key(p) == '%')
else
}
}
/* just extra escaped % chars. remove them. */
}
} else {
}
passwd_files = db;
return db;
}
{
/* no variables, open the file immediately */
}
}
{
struct db_passwd_file **p;
struct hash_iterate_context *iter;
return;
if (*p == db) {
break;
}
}
else {
}
}
}
static const char *
{
const char *p;
if (p == NULL)
return path;
/* most likely this is an invalid request. just cut off the '/' and
everything after it. */
return t_strdup_until(path, p);
}
struct passwd_user *
{
struct passwd_file *pw;
struct passwd_user *pu;
else {
const struct var_expand_table *table;
t_push();
/* doesn't exist yet. create lookup for it. */
}
t_pop();
}
t_push();
if (!passwd_file_sync(pw)) {
/* pw may be freed now */
"no passwd file: %s", path);
t_pop();
return NULL;
}
t_pop();
return pu;
}
#endif