#include <dirent.h> /* readdir() */
#include <sys/types.h>
#include <pwd.h>
-#include "cmdline.h" /* TODO: This file should be independent of command line options */
#include "user.h"
#include "fd.h"
#include "string.h"
return ui->flags & UI_FL_ADMISSIBLE;
}
-static int open_user_table(struct user_info *ui, int create)
+static int open_user_table(const char *dirname, struct user_info *ui, int create)
{
int ret;
struct passwd *pw;
ui->desc->num_columns = NUM_UT_COLUMNS;
ui->desc->flags = 0;
ui->desc->column_descriptions = user_table_cols;
- ui->desc->dir = adu_strdup(conf.database_dir_arg);
+ ui->desc->dir = adu_strdup(dirname);
ui->desc->name = make_message("%u", (unsigned)ui->uid);
pw = getpwuid(ui->uid);
if (pw && pw->pw_name)
*
* \return Standard.
*/
-int create_user_table(uint32_t uid, struct user_info **ui_ptr)
+int create_user_table(const char *dirname, uint32_t uid,
+ struct user_info **ui_ptr)
{
struct user_info *ui = lookup_uid(uid);
return 1;
ui->uid = uid;
ui->flags |= UI_FL_SLOT_USED;
- return open_user_table(ui, 1);
+ return open_user_table(dirname, ui, 1);
}
-static char *get_uid_list_name(void)
+static char *get_uid_list_name(const char *dirname)
{
- return make_message("%s/uid_list", conf.database_dir_arg);
+ return make_message("%s/uid_list", dirname);
}
/**
* Open the osl tables for all admissible uids.
*
* \return Stamdard.
*/
-int open_admissible_user_tables(struct uid_range *admissible_uids)
+int open_admissible_user_tables(const char *dirname,
+ struct uid_range *admissible_uids)
{
struct user_info *ui;
ui->flags |= UI_FL_ADMISSIBLE;
if (ui->table)
continue;
- ret = open_user_table(ui, 0);
+ ret = open_user_table(dirname, ui, 0);
if (ret < 0)
return ret;
}
*
* \return Standard.
*/
-int read_uid_file(void)
+int read_uid_file(const char *dirname)
{
size_t size;
uint32_t n;
- char *filename = get_uid_list_name(), *map;
+ char *filename = get_uid_list_name(dirname), *map;
int ret = mmap_full_file(filename, O_RDONLY, (void **)&map, &size, NULL);
unsigned bits;
*
* \return Standard.
*/
-int write_uid_file(void)
+int write_uid_file(const char *dirname)
{
char *buf, *p, *filename;
size_t size = num_uids * sizeof(uint32_t);
write_u32(p, ui->uid);
p += sizeof(uint32_t);
}
- filename = get_uid_list_name();
+ filename = get_uid_list_name(dirname);
ret = adu_write_file(filename, buf, size);
free(filename);
free(buf);
/** An opaque struct that contains info about which users are admissible. */
struct uid_range;
-int create_user_table(uint32_t uid, struct user_info **ui_ptr);
-int read_uid_file(void);
-int write_uid_file(void);
+int create_user_table(const char *dirname, uint32_t uid,
+ struct user_info **ui_ptr);
+int read_uid_file(const char *dirname);
+int write_uid_file(const char *dirname);
void create_hash_table(unsigned bits);
int for_each_admissible_user(int (*func)(struct user_info *, void *),
int append_users(char **users, int num_users,
struct uid_range **admissible_uids, int num_uid_ranges);
void close_user_tables(void);
-int open_admissible_user_tables(struct uid_range *admissible_uids);
+int open_admissible_user_tables(const char *dirname,
+ struct uid_range *admissible_uids);