Massively cleaned up #include's, so they're in a consistent
[freeradius.git] / src / modules / rlm_passwd / rlm_passwd.c
index 4df5c27..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];
@@ -354,7 +357,7 @@ 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 },
@@ -477,9 +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->delimiter != NULL)   free(inst->delimiter);
        free(instance);
        return 0;
 #undef inst
@@ -525,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;