Enable building #WITHOUT_PROXY
[freeradius.git] / src / modules / rlm_files / rlm_files.c
index f92aae8..e0bc59a 100644 (file)
@@ -38,27 +38,30 @@ struct file_instance {
 
        /* autz */
        char *usersfile;
-       lrad_hash_table_t *users;
+       fr_hash_table_t *users;
+
+
+       /* authenticate */
+       char *auth_usersfile;
+       fr_hash_table_t *auth_users;
 
        /* preacct */
        char *acctusersfile;
-       lrad_hash_table_t *acctusers;
+       fr_hash_table_t *acctusers;
 
+#ifdef WITH_PROXY
        /* pre-proxy */
        char *preproxy_usersfile;
-       lrad_hash_table_t *preproxy_users;
-
-       /* authenticate */
-       char *auth_usersfile;
-       lrad_hash_table_t *auth_users;
+       fr_hash_table_t *preproxy_users;
 
        /* post-proxy */
        char *postproxy_usersfile;
-       lrad_hash_table_t *postproxy_users;
+       fr_hash_table_t *postproxy_users;
+#endif
 
        /* post-authenticate */
        char *postauth_usersfile;
-       lrad_hash_table_t *postauth_users;
+       fr_hash_table_t *postauth_users;
 };
 
 
@@ -68,7 +71,7 @@ struct file_instance {
 static int fallthrough(VALUE_PAIR *vp)
 {
        VALUE_PAIR *tmp;
-       tmp = pairfind(vp, PW_FALL_THROUGH);
+       tmp = pairfind(vp, PW_FALL_THROUGH, 0);
 
        return tmp ? tmp->vp_integer : 0;
 }
@@ -78,12 +81,14 @@ static const CONF_PARSER module_config[] = {
          offsetof(struct file_instance,usersfile), NULL, NULL },
        { "acctusersfile", PW_TYPE_FILENAME,
          offsetof(struct file_instance,acctusersfile), NULL, NULL },
+#ifdef WITH_PROXY
        { "preproxy_usersfile", PW_TYPE_FILENAME,
          offsetof(struct file_instance,preproxy_usersfile), NULL, NULL },
-       { "auth_usersfile", PW_TYPE_FILENAME,
-         offsetof(struct file_instance,auth_usersfile), NULL, NULL },
        { "postproxy_usersfile", PW_TYPE_FILENAME,
          offsetof(struct file_instance,postproxy_usersfile), NULL, NULL },
+#endif
+       { "auth_usersfile", PW_TYPE_FILENAME,
+         offsetof(struct file_instance,auth_usersfile), NULL, NULL },
        { "postauth_usersfile", PW_TYPE_FILENAME,
          offsetof(struct file_instance,postauth_usersfile), NULL, NULL },
        { "compat",        PW_TYPE_STRING_PTR,
@@ -96,7 +101,7 @@ static const CONF_PARSER module_config[] = {
 
 static uint32_t pairlist_hash(const void *data)
 {
-       return lrad_hash_string(((const PAIR_LIST *)data)->name);
+       return fr_hash_string(((const PAIR_LIST *)data)->name);
 }
 
 static int pairlist_cmp(const void *a, const void *b)
@@ -113,13 +118,13 @@ static void my_pairlist_free(void *data)
 }
 
 
-static int getusersfile(const char *filename, lrad_hash_table_t **pht,
+static int getusersfile(const char *filename, fr_hash_table_t **pht,
                        char *compat_mode_str)
 {
        int rcode;
        PAIR_LIST *users = NULL;
        PAIR_LIST *entry, *next;
-       lrad_hash_table_t *ht, *tailht;
+       fr_hash_table_t *ht, *tailht;
        int order = 0;
 
        if (!filename) {
@@ -174,7 +179,7 @@ static int getusersfile(const char *filename, lrad_hash_table_t **pht,
                                 *      or it's a wire protocol,
                                 *      ensure it has '=='.
                                 */
-                               if (((vp->attribute & ~0xffff) != 0) ||
+                               if ((vp->vendor != 0) ||
                                                (vp->attribute < 0x100)) {
                                        if (!compat_mode) {
                                                DEBUG("[%s]:%d WARNING! Changing '%s =' to '%s =='\n\tfor comparing RADIUS attribute in check item list for user %s",
@@ -235,7 +240,7 @@ static int getusersfile(const char *filename, lrad_hash_table_t **pht,
                                 *      then bitch about it, giving a
                                 *      good warning message.
                                 */
-                               if (!(vp->attribute & ~0xffff) &&
+                                if ((vp->vendor == 0) &&
                                        (vp->attribute > 0xff) &&
                                        (vp->attribute > 1000)) {
                                        log_debug("[%s]:%d WARNING! Check item \"%s\"\n"
@@ -252,17 +257,17 @@ static int getusersfile(const char *filename, lrad_hash_table_t **pht,
 
        }
 
-       ht = lrad_hash_table_create(pairlist_hash, pairlist_cmp,
+       ht = fr_hash_table_create(pairlist_hash, pairlist_cmp,
                                    my_pairlist_free);
        if (!ht) {
                pairlist_free(&users);
                return -1;
        }
 
-       tailht = lrad_hash_table_create(pairlist_hash, pairlist_cmp,
+       tailht = fr_hash_table_create(pairlist_hash, pairlist_cmp,
                                        NULL);
        if (!tailht) {
-               lrad_hash_table_free(ht);
+               fr_hash_table_free(ht);
                pairlist_free(&users);
                return -1;
        }
@@ -282,30 +287,30 @@ static int getusersfile(const char *filename, lrad_hash_table_t **pht,
                 *      Insert it into the hash table, and remember
                 *      the tail of the linked list.
                 */
-               tail = lrad_hash_table_finddata(tailht, entry);
+               tail = fr_hash_table_finddata(tailht, entry);
                if (!tail) {
                        /*
                         *      Insert it into the head & tail.
                         */
-                       if (!lrad_hash_table_insert(ht, entry) ||
-                           !lrad_hash_table_insert(tailht, entry)) {
+                       if (!fr_hash_table_insert(ht, entry) ||
+                           !fr_hash_table_insert(tailht, entry)) {
                                pairlist_free(&next);
-                               lrad_hash_table_free(ht);
-                               lrad_hash_table_free(tailht);
+                               fr_hash_table_free(ht);
+                               fr_hash_table_free(tailht);
                                return -1;
                        }
                } else {
                        tail->next = entry;
-                       if (!lrad_hash_table_replace(tailht, entry)) {
+                       if (!fr_hash_table_replace(tailht, entry)) {
                                pairlist_free(&next);
-                               lrad_hash_table_free(ht);
-                               lrad_hash_table_free(tailht);
+                               fr_hash_table_free(ht);
+                               fr_hash_table_free(tailht);
                                return -1;
                        }
                }
        }
 
-       lrad_hash_table_free(tailht);
+       fr_hash_table_free(tailht);
        *pht = ht;
 
        return 0;
@@ -317,12 +322,14 @@ static int getusersfile(const char *filename, lrad_hash_table_t **pht,
 static int file_detach(void *instance)
 {
        struct file_instance *inst = instance;
-       lrad_hash_table_free(inst->users);
-       lrad_hash_table_free(inst->acctusers);
-       lrad_hash_table_free(inst->preproxy_users);
-       lrad_hash_table_free(inst->auth_users);
-       lrad_hash_table_free(inst->postproxy_users);
-       lrad_hash_table_free(inst->postauth_users);
+       fr_hash_table_free(inst->users);
+       fr_hash_table_free(inst->acctusers);
+#ifdef WITH_PROXY
+       fr_hash_table_free(inst->preproxy_users);
+       fr_hash_table_free(inst->postproxy_users);
+#endif
+       fr_hash_table_free(inst->auth_users);
+       fr_hash_table_free(inst->postauth_users);
        free(inst);
        return 0;
 }
@@ -362,6 +369,7 @@ static int file_instantiate(CONF_SECTION *conf, void **instance)
                return -1;
        }
 
+#ifdef WITH_PROXY
        /*
         *  Get the pre-proxy stuff
         */
@@ -372,16 +380,17 @@ static int file_instantiate(CONF_SECTION *conf, void **instance)
                return -1;
        }
 
-       rcode = getusersfile(inst->auth_usersfile, &inst->auth_users, inst->compat_mode);
+       rcode = getusersfile(inst->postproxy_usersfile, &inst->postproxy_users, inst->compat_mode);
        if (rcode != 0) {
-               radlog(L_ERR|L_CONS, "Errors reading %s", inst->auth_usersfile);
+               radlog(L_ERR|L_CONS, "Errors reading %s", inst->postproxy_usersfile);
                file_detach(inst);
                return -1;
        }
+#endif
 
-       rcode = getusersfile(inst->postproxy_usersfile, &inst->postproxy_users, inst->compat_mode);
+       rcode = getusersfile(inst->auth_usersfile, &inst->auth_users, inst->compat_mode);
        if (rcode != 0) {
-               radlog(L_ERR|L_CONS, "Errors reading %s", inst->postproxy_usersfile);
+               radlog(L_ERR|L_CONS, "Errors reading %s", inst->auth_usersfile);
                file_detach(inst);
                return -1;
        }
@@ -401,7 +410,7 @@ static int file_instantiate(CONF_SECTION *conf, void **instance)
  *     Common code called by everything below.
  */
 static int file_common(struct file_instance *inst, REQUEST *request,
-                      const char *filename, lrad_hash_table_t *ht,
+                      const char *filename, fr_hash_table_t *ht,
                       VALUE_PAIR *request_pairs, VALUE_PAIR **reply_pairs)
 {
        const char      *name, *match;
@@ -432,9 +441,9 @@ static int file_common(struct file_instance *inst, REQUEST *request,
        if (!ht) return RLM_MODULE_NOOP;
 
        my_pl.name = name;
-       user_pl = lrad_hash_table_finddata(ht, &my_pl);
+       user_pl = fr_hash_table_finddata(ht, &my_pl);
        my_pl.name = "DEFAULT";
-       default_pl = lrad_hash_table_finddata(ht, &my_pl);
+       default_pl = fr_hash_table_finddata(ht, &my_pl);
 
        /*
         *      Find the entry for the user.
@@ -464,7 +473,7 @@ static int file_common(struct file_instance *inst, REQUEST *request,
                }
 
                if (paircompare(request, request_pairs, pl->check, reply_pairs) == 0) {
-                       DEBUG2("    %s: Matched entry %s at line %d",
+                       RDEBUG2("%s: Matched entry %s at line %d",
                               filename, match, pl->lineno);
                        found = 1;
                        check_tmp = paircopy(pl->check);
@@ -485,7 +494,7 @@ static int file_common(struct file_instance *inst, REQUEST *request,
        /*
         *      Remove server internal parameters.
         */
-       pairdelete(reply_pairs, PW_FALL_THROUGH);
+       pairdelete(reply_pairs, PW_FALL_THROUGH, 0);
 
        /*
         *      See if we succeeded.
@@ -526,6 +535,7 @@ static int file_preacct(void *instance, REQUEST *request)
                           request->packet->vps, &request->reply->vps);
 }
 
+#ifdef WITH_PROXY
 static int file_preproxy(void *instance, REQUEST *request)
 {
        struct file_instance *inst = instance;
@@ -543,6 +553,7 @@ static int file_postproxy(void *instance, REQUEST *request)
                           inst->postproxy_users,
                           request->proxy_reply->vps, &request->reply->vps);
 }
+#endif
 
 static int file_authenticate(void *instance, REQUEST *request)
 {
@@ -567,7 +578,7 @@ static int file_postauth(void *instance, REQUEST *request)
 module_t rlm_files = {
        RLM_MODULE_INIT,
        "files",
-       RLM_TYPE_CHECK_CONFIG_SAFE,     /* type: reserved */
+       RLM_TYPE_CHECK_CONFIG_SAFE | RLM_TYPE_HUP_SAFE,
        file_instantiate,               /* instantiation */
        file_detach,                    /* detach */
        {
@@ -576,8 +587,12 @@ module_t rlm_files = {
                file_preacct,           /* preaccounting */
                NULL,                   /* accounting */
                NULL,                   /* checksimul */
+#ifdef WITH_PROXY
                file_preproxy,          /* pre-proxy */
                file_postproxy,         /* post-proxy */
+#else
+               NULL, NULL,
+#endif
                file_postauth           /* post-auth */
        },
 };