fd.c: Avoid gcc warning regarding fchdir().
[adu.git] / user.c
diff --git a/user.c b/user.c
index dfa1c103a9211e1a78e5e0502b0537e4a22cb885..ed16463afed9372426c5c08284a65ec863a19e2e 100644 (file)
--- a/user.c
+++ b/user.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2008 Andre Noll <maan@tuebingen.mpg.de>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -44,7 +44,7 @@ enum uid_info_flags {
  *
  * Even users that are not taken into account because of the --uid
  * option occupy a slot in this hash table. This allows to find out
- * quicky whether a uid is admissible. And yes, this has to be fast.
+ * quickly whether a uid is admissible. And yes, this has to be fast.
  */
 static struct user_info *uid_hash_table;
 
@@ -257,7 +257,7 @@ static inline int ui_admissible(struct user_info *ui)
        return ui->flags & UI_FL_ADMISSIBLE;
 }
 
-static int open_user_table(const char *dirname, struct user_info *ui, int create)
+static int open_user_table(struct user_info *ui, int create)
 {
        int ret;
        struct passwd *pw;
@@ -266,7 +266,7 @@ static int open_user_table(const char *dirname, struct user_info *ui, int create
        ui->desc->num_columns = NUM_UT_COLUMNS;
        ui->desc->flags = 0;
        ui->desc->column_descriptions = user_table_cols;
-       ui->desc->dir = adu_strdup(dirname);
+       ui->desc->dir = adu_strdup(database_dir);
        ui->desc->name = make_message("%u", (unsigned)ui->uid);
        pw = getpwuid(ui->uid);
        if (pw && pw->pw_name)
@@ -435,8 +435,7 @@ static struct user_info *lookup_uid(uint32_t uid)
  *
  * \return Standard.
  */
-int create_user_table(const char *dirname, uint32_t uid,
-               struct user_info **ui_ptr)
+int create_user_table(uint32_t uid, struct user_info **ui_ptr)
 {
        struct user_info *ui = lookup_uid(uid);
 
@@ -447,12 +446,12 @@ int create_user_table(const char *dirname, uint32_t uid,
                return 1;
        ui->uid = uid;
        ui->flags |= UI_FL_SLOT_USED;
-       return open_user_table(dirname, ui, 1);
+       return open_user_table(ui, 1);
 }
 
-static char *get_uid_list_name(const char *dirname)
+static char *get_uid_list_name(void)
 {
-       return make_message("%s/uid_list", dirname);
+       return make_message("%s/uid_list", database_dir);
 }
 /**
  * Open the osl tables for all admissible uids.
@@ -467,10 +466,9 @@ static char *get_uid_list_name(const char *dirname)
  * \a admissible_uids. If so, it sets the admissible bit for this slot and
  * opens the osl table of the uid.
  *
- * \return Stamdard.
+ * \return Standard.
  */
-int open_admissible_user_tables(const char *dirname,
-               struct uid_range *admissible_uids)
+int open_admissible_user_tables(struct uid_range *admissible_uids)
 {
        struct user_info *ui;
 
@@ -489,7 +487,7 @@ int open_admissible_user_tables(const char *dirname,
                ui->flags |= UI_FL_ADMISSIBLE;
                if (ui->table)
                        continue;
-               ret = open_user_table(dirname, ui, 0);
+               ret = open_user_table(ui, 0);
                if (ret < 0)
                        return ret;
        }
@@ -508,12 +506,12 @@ int open_admissible_user_tables(const char *dirname,
  *
  * \return Standard.
  */
-int read_uid_file(const char *dirname)
+int read_uid_file(void)
 {
        size_t size;
        uint32_t n;
-       char *filename = get_uid_list_name(dirname), *map;
-       int ret = mmap_full_file(filename, O_RDONLY, (void **)&map, &size, NULL);
+       char *filename = get_uid_list_name(), *map;
+       int ret = mmap_file_ro(filename, (void **)&map, &size);
        unsigned bits;
 
        if (ret < 0) {
@@ -562,7 +560,7 @@ out:
  *
  * \return Standard.
  */
-int write_uid_file(const char *dirname)
+int write_uid_file(void)
 {
        char *buf, *p, *filename;
        size_t size = num_uids * sizeof(uint32_t);
@@ -578,7 +576,7 @@ int write_uid_file(const char *dirname)
                write_u32(p, ui->uid);
                p += sizeof(uint32_t);
        }
-       filename = get_uid_list_name(dirname);
+       filename = get_uid_list_name();
        ret = adu_write_file(filename, buf, size);
        free(filename);
        free(buf);