*
* 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 "libradius.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;
struct mypasswd *last_found;
char buffer[1024];
FILE *fp;
- char *delimiter;
+ char delimiter;
};
}
static int string_to_entry(const char* string, int nfields, char delimiter,
- struct mypasswd *passwd, int bufferlen)
+ struct mypasswd *passwd, size_t bufferlen)
{
char *str;
- int len, i, fn=0;
+ size_t len, i;
+ int fn=0;
char *data_beg;
if(!len) return 0;
if (string[len-1] == '\r') len--;
if(!len) return 0;
- if (!len || !passwd || bufferlen < (len + nfields * sizeof (char*) + nfields * sizeof (char) + sizeof (struct mypasswd) + 1) ) return 0;
+ if (!len || !passwd ||
+ bufferlen < (len + nfields * sizeof (char*) + nfields * sizeof (char) + sizeof (struct mypasswd) + 1) ) return 0;
passwd->next = NULL;
data_beg=(char *)passwd + sizeof(struct mypasswd);
str = data_beg + nfields * sizeof (char) + nfields * sizeof (char*);
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){
}
static struct hashtable * build_hash_table (const char * file, int nfields,
- int keyfield, int islist, int tablesize, int ignorenis, char * delimiter)
+ int keyfield, int islist, int tablesize, int ignorenis, char delimiter)
{
#define passwd ((struct mypasswd *) ht->buffer)
char buffer[1024];
struct hashtable* ht;
- int len;
+ size_t len;
unsigned int h;
struct mypasswd *hashentry, *hashentry1;
char *list;
ht->keyfield = keyfield;
ht->islist = islist;
ht->ignorenis = ignorenis;
- if (delimiter && *delimiter) ht->delimiter = delimiter;
- else ht->delimiter = ":";
+ if (delimiter) ht->delimiter = delimiter;
+ else ht->delimiter = ':';
if(!tablesize) return ht;
if(!(ht->fp = fopen(file,"r"))) return NULL;
memset(ht->buffer, 0, 1024);
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);
+ len = string_to_entry(buffer, nfields, ht->delimiter, hashentry, len);
if(!hashentry->field[keyfield] || *hashentry->field[keyfield] == '\0') {
free(hashentry);
continue;
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];
}
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)) &&
+ if(*buffer && *buffer!='\n' && (len = string_to_entry(buffer, ht->nfields, ht->delimiter, passwd, sizeof(ht->buffer)-1)) &&
(!ht->ignorenis || (*buffer !='-' && *buffer != '+') ) ){
if(!ht->islist) {
if(!strcmp(passwd->field[ht->keyfield], name))
struct mypasswd *pwdfmt;
char *filename;
char *format;
- char *authtype;
char * delimiter;
int allowmultiple;
int ignorenislike;
int ignoreempty;
};
-static CONF_PARSER module_config[] = {
- { "filename", PW_TYPE_STRING_PTR,
+static const CONF_PARSER module_config[] = {
+ { "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,
radlog(L_ERR, "rlm_passwd: no field market as key in format: %s", inst->format);
return -1;
}
- if (! (inst->ht = build_hash_table (inst->filename, nfields, keyfield, listable, inst->hashsize, inst->ignorenislike, inst->delimiter)) ){
+ if (! (inst->ht = build_hash_table (inst->filename, nfields, keyfield, listable, inst->hashsize, inst->ignorenislike, *inst->delimiter)) ){
radlog(L_ERR, "rlm_passwd: can't build hashtable from passwd file");
return -1;
}
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
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
name = buffer;
break;
default:
- name = key->strvalue;
+ name = key->vp_strvalue;
}
if (! (pw = get_pw_nam(name, inst->ht)) ) {
continue;
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 */
NULL, /* post-proxy */
NULL /* post-auth */
},
- passwd_detach, /* detach */
- NULL /* destroy */
};
#endif /* TEST */