if (!dir_table)
return;
+ NOTICE_LOG("closing dir table\n");
ret = osl(osl_close_table(dir_table, OSL_MARK_CLEAN));
if (ret < 0)
ERROR_LOG("failed to close dir table: %s\n", adu_strerror(-ret));
int open_dir_table(int create)
{
+
+ if (dir_table)
+ return 1;
dir_table_desc.dir = adu_strdup(conf.database_dir_arg);
if (create) {
+ NOTICE_LOG("creating dir table\n");
int ret = osl(osl_create_table(&dir_table_desc));
if (ret < 0) {
free((char *)dir_table_desc.dir);
return ret;
}
}
+ INFO_LOG("opening dir table\n");
return osl(osl_open_table(&dir_table_desc, &dir_table));
}
if (ret < 0)
goto out;
out:
+ close_all_tables();
if (ret < 0) {
ERROR_LOG("%s\n", adu_strerror(-ret));
return -EXIT_FAILURE;
goto out;
ret = write_uid_file();
out:
- close_all_tables();
return ret;
}
static int icom_reset(__a_unused char *line)
{
+ NOTICE_LOG("resetting configuration to default\n");
free_format_info(fi);
fi = NULL;
free(admissible_uids);
admissible_uids = NULL;
select_cmdline_parser_init(&select_conf);
- return 1;
+ return parse_select_options(NULL, NULL, &admissible_uids, &fi);
}
static int icom_set(char *line)
{
+ int ret;
struct select_cmdline_parser_params params = {
.override = 1,
.initialize = 0,
fi = NULL;
free(admissible_uids);
admissible_uids = NULL;
- return parse_select_options(line, ¶ms, &admissible_uids, &fi);
+ ret = parse_select_options(line, ¶ms, &admissible_uids, &fi);
+ if (ret >= 0)
+ return ret;
+ return icom_reset(NULL);
}
static int exec_interactive_command(char *line)
select_cmdline_parser_init(&select_conf);
ret = parse_select_options(NULL, NULL, &admissible_uids, &fi);
+ if (ret< 0)
+ return ret;
+ ret = read_uid_file();
+ if (ret < 0)
+ return ret;
while (read_input_line(line, sizeof(line)) >= 0) {
ret = exec_interactive_command(line);
if (ret < 0)
if (ret < 0)
goto out;
check_signals();
- ret = read_uid_file(admissible_uids);
+ ret = open_admissible_user_tables(admissible_uids);
if (ret < 0)
goto out;
check_signals();
ret = print_statistics(fi);
out:
- close_all_tables();
if (output_file && output_file != stdout) {
fclose(output_file);
output_file = NULL;
ret = parse_select_options(conf.select_options_arg, ¶ms,
&admissible_uids, &fi);
if (ret > 0) {
+ ret = read_uid_file();
+ if (ret < 0)
+ goto out;
ret = run_select_query(admissible_uids, fi);
free_format_info(fi);
}
+out:
select_cmdline_parser_free(&select_conf);
return ret;
}
if (pw && pw->pw_name)
ui->pw_name = adu_strdup(pw->pw_name);
- DEBUG_LOG("opening table for uid %u\n", (unsigned)ui->uid);
+ INFO_LOG("opening table for uid %u\n", (unsigned)ui->uid);
if (create) {
ret = osl(osl_create_table(ui->desc));
if (ret < 0)
continue;
if (!ui->table)
continue;
- DEBUG_LOG("closing user table for uid %u\n", (unsigned)ui->uid);
+ INFO_LOG("closing user table for uid %u\n", (unsigned)ui->uid);
ret = osl(osl_close_table(ui->table, OSL_MARK_CLEAN));
if (ret < 0)
ERROR_LOG("failed to close user table %u: %s\n",
comp);
}
-int read_uid_file(struct uid_range *admissible_uids)
+int open_admissible_user_tables(struct uid_range *admissible_uids)
+{
+ struct user_info *ui;
+
+ assert(uid_hash_table);
+ DEBUG_LOG("size: %d\n", uid_hash_table_size);
+ FOR_EACH_USER(ui) {
+ int ret;
+
+ if (!ui_used(ui)) {
+ continue;
+ }
+ if (!uid_is_admissible(ui->uid, admissible_uids)) {
+ DEBUG_LOG("uid %u is not admissible\n", ui->uid);
+ ui->flags &= ~UI_FL_ADMISSIBLE;
+ continue;
+ }
+ ui->flags |= UI_FL_ADMISSIBLE;
+ if (ui->table)
+ continue;
+ ret = open_user_table(ui, 0);
+ if (ret < 0)
+ return ret;
+ }
+ return 1;
+}
+
+int read_uid_file(void)
{
size_t size;
uint32_t n;
assert(ui);
if (ui_used(ui)) { /* impossible */
ERROR_LOG("duplicate user id!?\n");
- ret =-EFAULT;
+ ret = -EFAULT;
goto out;
}
ui->uid = uid;
ui->flags |= UI_FL_SLOT_USED;
- if (!uid_is_admissible(uid, admissible_uids))
- continue;
- ui->flags |= UI_FL_ADMISSIBLE;
- ret = open_user_table(ui, 0);
- if (ret < 0)
- return ret;
}
ret = 1;
out:
struct uid_range;
int create_user_table(uint32_t uid, struct user_info **ui_ptr);
-int read_uid_file(struct uid_range *admissible_uids);
+int read_uid_file(void);
int write_uid_file(void);
void create_hash_table(unsigned bits);
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);