Massively cleaned up #include's, so they're in a consistent
[freeradius.git] / src / modules / rlm_passwd / rlm_passwd.c
index 8cc54ad..632f8d7 100644 (file)
  *
  *   You should have received a copy of the GNU General Public License
  *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  *
- * Copyright 2000  The FreeRADIUS server project
+ * Copyright 2000,2006  The FreeRADIUS server project
  */
 
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include "autoconf.h"
-#include "radiusd.h"
-#include "modules.h"
+#include <freeradius-devel/ident.h>
+RCSID("$Id$")
 
+#include <freeradius-devel/radiusd.h>
+#include <freeradius-devel/modules.h>
 
 struct mypasswd {
        struct mypasswd *next;
@@ -133,12 +131,19 @@ static unsigned int hash(const unsigned char * username, unsigned int tablesize)
 static void release_hash_table(struct hashtable * ht){
        int i;
 
-       if (!ht) return;
-       for (i=0; i<ht->tablesize; i++)
+       if (ht == NULL) return;
+       for (i = 0; i < ht->tablesize; i++)
                if (ht->table[i])
                        destroy_password(ht->table[i]);
-       if (ht->table) free(ht->table);
-       if (ht->fp) fclose(ht->fp);
+       if (ht->table) {
+               free(ht->table);
+               ht->table = NULL;
+       }
+       if (ht->fp) {
+               fclose(ht->fp);
+               ht->fp = NULL;
+       }
+       ht->tablesize = 0;
 }
 
 static void release_ht(struct hashtable * ht){
@@ -195,7 +200,6 @@ static struct hashtable * build_hash_table (const char * file, int nfields,
                if(*buffer && *buffer!='\n' && (!ignorenis || (*buffer != '+' && *buffer != '-')) ){
                        if(!(hashentry = mypasswd_malloc(buffer, nfields, &len))){
                                release_hash_table(ht);
-                               ht->tablesize = 0;
                                return ht;
                        }
                        len = string_to_entry(buffer, nfields, ht->delimiter, hashentry, len);
@@ -220,7 +224,6 @@ static struct hashtable * build_hash_table (const char * file, int nfields,
                                        else nextlist = 0;
                                        if(!(hashentry1 = mypasswd_malloc("", nfields, &len))){
                                                release_hash_table(ht);
-                                               ht->tablesize = 0;
                                                return ht;
                                        }
                                        for (i=0; i<nfields; i++) hashentry1->field[i] = hashentry->field[i];
@@ -258,7 +261,7 @@ static struct mypasswd * get_next(char *name, struct hashtable *ht)
                }
                return NULL;
        }
-       printf("try to find in file\n");
+       /*      printf("try to find in file\n"); */
        if (!ht->fp) return NULL;
        while (fgets(buffer, 1024,ht->fp)) {
                if(*buffer && *buffer!='\n' && (len = string_to_entry(buffer, ht->nfields, ht->delimiter, passwd, sizeof(ht->buffer)-1)) &&
@@ -341,7 +344,6 @@ struct passwd_instance {
        struct mypasswd *pwdfmt;
        char *filename;
        char *format;
-       char *authtype;
        char * delimiter;
        int allowmultiple;
        int ignorenislike;
@@ -355,12 +357,10 @@ struct passwd_instance {
 };
 
 static const CONF_PARSER module_config[] = {
-       { "filename",   PW_TYPE_STRING_PTR,
+       { "filename",   PW_TYPE_FILENAME,
           offsetof(struct passwd_instance, filename), NULL,  NULL },
        { "format",   PW_TYPE_STRING_PTR,
           offsetof(struct passwd_instance, format), NULL,  NULL },
-       { "authtype",   PW_TYPE_STRING_PTR,
-          offsetof(struct passwd_instance, authtype), NULL,  NULL },
        { "delimiter",   PW_TYPE_STRING_PTR,
           offsetof(struct passwd_instance, delimiter), NULL,  ":" },
        { "ignorenislike",   PW_TYPE_BOOLEAN,
@@ -471,7 +471,7 @@ static int passwd_instantiate(CONF_SECTION *conf, void **instance)
        inst->nfields = nfields;
        inst->keyfield = keyfield;
        inst->listable = listable;
-       radlog(L_INFO, "rlm_passwd: nfields: %d keyfield %d(%s) listable: %s", nfields, keyfield, inst->pwdfmt->field[keyfield], listable?"yes":"no");
+       DEBUG("rlm_passwd: nfields: %d keyfield %d(%s) listable: %s", nfields, keyfield, inst->pwdfmt->field[keyfield], listable?"yes":"no");
        return 0;
 
 #undef inst
@@ -480,10 +480,6 @@ static int passwd_instantiate(CONF_SECTION *conf, void **instance)
 static int passwd_detach (void *instance) {
 #define inst ((struct passwd_instance *)instance)
        if(inst->ht) release_ht(inst->ht);
-        if (inst->filename != NULL)    free(inst->filename);
-        if (inst->format != NULL)      free(inst->format);
-        if (inst->authtype != NULL )   free(inst->authtype);
-        if (inst->delimiter != NULL)   free(inst->delimiter);
        free(instance);
        return 0;
 #undef inst
@@ -529,7 +525,7 @@ static int passwd_authorize(void *instance, REQUEST *request)
                                name = buffer;
                                break;
                        default:
-                               name = key->strvalue;
+                               name = key->vp_strvalue;
                }
                if (! (pw = get_pw_nam(name, inst->ht)) ) {
                        continue;
@@ -545,27 +541,17 @@ static int passwd_authorize(void *instance, REQUEST *request)
        if(!found) {
                return RLM_MODULE_NOTFOUND;
        }
-       if (inst->authtype &&
-           (key = pairmake ("Auth-Type", inst->authtype, T_OP_EQ))) {
-               radlog(L_INFO, "rlm_passwd: Adding \"Auth-Type = %s\"",
-                      inst->authtype);
-               /*
-                *      Don't call pairadd.  pairmove doesn't
-                *      over-write existing attributes.
-                */
-               pairmove(&request->config_items, &key);
-               pairfree(&key); /* pairmove may have NOT moved it */
-       }
        return RLM_MODULE_OK;
 
 #undef inst
 }
 
 module_t rlm_passwd = {
+       RLM_MODULE_INIT,
        "passwd",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialize */
        passwd_instantiate,             /* instantiation */
+       passwd_detach,                  /* detach */
        {
                NULL,                   /* authentication */
                passwd_authorize,       /* authorization */
@@ -576,7 +562,5 @@ module_t rlm_passwd = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       passwd_detach,                  /* detach */
-       NULL                            /* destroy */
 };
 #endif /* TEST */