24 RCSID(
"$Id: 8ca82f1c40e3db66f21a2ed7d36280afbbb219b8 $")
26 #include <freeradius-devel/radiusd.h>
27 #include <freeradius-devel/modules.h>
28 #include <freeradius-devel/rad_assert.h>
52 #define rad_malloc(s) malloc(s)
54 void printpw(
struct mypasswd *pw,
int nfields){
57 for( i = 0; i < nfields; i++ ) printf(
"%s:", pw->
field[i]);
60 else printf (
"Not found\n");
72 *len=
sizeof (
struct mypasswd) + nfields *
sizeof (
char*) + nfields *
sizeof (
char ) + strlen(buffer) + 1;
74 if (t) memset(t, 0, *len);
79 struct mypasswd *passwd,
size_t bufferlen)
89 if (
string[len-1] ==
'\n') len--;
91 if (
string[len-1] ==
'\r') len--;
93 if (!len || !passwd ||
94 bufferlen < (len + nfields *
sizeof (
char*) + nfields *
sizeof (
char) +
sizeof (
struct mypasswd) + 1) )
return 0;
96 data_beg=(
char *)passwd +
sizeof(
struct mypasswd);
97 str = data_beg + nfields *
sizeof (char) + nfields *
sizeof (
char*);
98 memcpy (str,
string, len);
100 passwd->
field[fn++] = str;
101 passwd->
listflag = data_beg + nfields *
sizeof (
char *);
102 for(i=0; i < len; i++){
103 if (str[i] == delimiter) {
105 passwd->
field[fn++] = str + i + 1;
106 if (fn == nfields)
break;
109 for (; fn < nfields; fn++) passwd->
field[fn] = NULL;
110 return len + nfields * sizeof (
char) + nfields *
sizeof (
char*) +
sizeof (
struct mypasswd) + 1;
117 while ((p=pass)!=NULL) {
124 static unsigned int hash(
char const * username,
unsigned int tablesize)
128 h = h * 7907 + *username++;
167 struct mypasswd *hashentry, *hashentry1;
190 if(!tablesize)
return ht;
191 if(!(ht->
fp = fopen(file,
"r"))) {
202 memset(ht->
buffer, 0, 1024);
213 while (fgets(buffer, 1024, ht->
fp)) {
214 if(*buffer && *buffer!=
'\n' && (!ignorenis || (*buffer !=
'+' && *buffer !=
'-')) ){
220 if(!hashentry->
field[keyfield] || *hashentry->
field[keyfield] ==
'\0') {
226 list = hashentry->
field[keyfield];
227 for (nextlist = list; *nextlist && *nextlist!=
','; nextlist++);
228 if (*nextlist) *nextlist++ = 0;
231 h =
hash(hashentry->
field[keyfield], tablesize);
233 ht->
table[h] = hashentry;
235 for(list=nextlist; nextlist; list = nextlist){
236 for (nextlist = list; *nextlist && *nextlist!=
','; nextlist++);
237 if (*nextlist) *nextlist++ = 0;
243 for (i=0; i<nfields; i++) hashentry1->
field[i] = hashentry->
field[i];
244 hashentry1->
field[keyfield] = list;
245 h =
hash(list, tablesize);
247 ht->
table[h] = hashentry1;
264 char *list, *nextlist;
268 hashentry = *last_found;
269 for (; hashentry; hashentry = hashentry->
next) {
272 *last_found = hashentry->
next;
279 if (!ht->
fp)
return NULL;
283 while (fgets(buffer, 1024,ht->
fp)) {
285 (!ht->
ignorenis || (*buffer !=
'-' && *buffer !=
'+') ) ){
291 for (list = passwd->
field[ht->
keyfield], nextlist = list; nextlist; list = nextlist) {
292 for(nextlist = list; *nextlist && *nextlist!=
','; nextlist++);
298 if (!strcmp(list, name)) {
317 if (!ht || !name || *name ==
'\0')
return NULL;
321 for (hashentry = ht->
table[h]; hashentry; hashentry = hashentry->
next) {
324 *last_found=hashentry->
next;
335 if (!(ht->
fp=fopen(ht->
filename,
"r")))
return NULL;
336 return get_next(name, ht, last_found);
341 #define MALLOC_CHECK_ 1
351 printf(
"Hash table not built\n");
357 for (pw = ht->
table[i]; pw; pw = pw->
next) {
363 while(fgets(buffer, 1024, stdin)){
364 buffer[strlen(buffer)-1] = 0;
367 while ((pw =
get_next(buffer, ht, &last_found))) printpw(pw,4);
406 int nfields=0, keyfield=-1, listable=0;
424 ERROR(
"rlm_passwd: memory allocation failed for lf");
427 memset(lf, 0, strlen(inst->
format));
430 if(s == inst->
format - 1 || *s ==
':'){
457 ERROR(
"rlm_passwd: can't build hashtable from passwd file");
461 ERROR(
"rlm_passwd: memory allocation failed");
467 ERROR(
"rlm_passwd: unable to convert format entry");
476 for (i=0; i<nfields; i++) {
489 ERROR(
"rlm_passwd: unable to resolve attribute: %s", inst->
pwdfmt->
field[keyfield]);
498 DEBUG2(
"rlm_passwd: nfields: %d keyfield %d(%s) listable: %s", nfields, keyfield, inst->
pwdfmt->
field[keyfield], listable?
"yes":
"no");
505 #define inst ((rlm_passwd_t *)instance)
521 for (i = 0; i < inst->
nfields; i++) {
536 #define inst ((rlm_passwd_t *)instance)
558 addresult(request,
inst, request, &request->config, pw, 0,
"config");
559 addresult(request->reply,
inst, request, &request->reply->vps, pw, 1,
"reply_items");
560 addresult(request->packet,
inst, request, &request->packet->vps, pw, 2,
"request_items");
561 }
while ((pw =
get_next(buffer,
inst->ht, &last_found)));
563 if (!
inst->allow_multiple) {
579 .config = module_config,
static const CONF_PARSER module_config[]
5 methods index for preproxy section.
#define PW_TYPE_FILE_INPUT
File matching value must exist, and must be readable.
static void destroy_password(struct mypasswd *pass)
static void release_hash_table(struct hashtable *ht)
The module is OK, continue.
static int mod_instantiate(CONF_SECTION *conf, void *instance)
Metadata exported by the module.
VALUE_PAIR * fr_cursor_next_by_num(vp_cursor_t *cursor, unsigned int vendor, unsigned int attr, int8_t tag)
Iterate over a collection of VALUE_PAIRs of a given type in the pairlist.
void * rad_malloc(size_t size)
static struct mypasswd * get_next(char *name, struct hashtable *ht, struct mypasswd **last_found)
7 methods index for postauth section.
static void release_ht(struct hashtable *ht)
void size_t fr_pair_value_snprint(char *out, size_t outlen, VALUE_PAIR const *vp, char quote)
Print the value of an attribute to a string.
#define CONF_PARSER_TERMINATOR
VALUE_PAIR * fr_cursor_init(vp_cursor_t *cursor, VALUE_PAIR *const *node)
Setup a cursor to iterate over attribute pairs.
static struct mypasswd * get_pw_nam(char *name, struct hashtable *ht, struct mypasswd **last_found)
#define RLM_TYPE_HUP_SAFE
Will be restarted on HUP.
static int string_to_entry(char const *string, int nfields, char delimiter, struct mypasswd *passwd, size_t bufferlen)
Defines a CONF_PAIR to C data type mapping.
Abstraction to allow iterating over different configurations of VALUE_PAIRs.
static unsigned int hash(char const *username, unsigned int tablesize)
static rlm_rcode_t CC_HINT(nonnull)
struct rlm_passwd_t rlm_passwd_t
3 methods index for accounting section.
Stores an attribute, a value and various bits of other data.
void void cf_log_err_cs(CONF_SECTION const *cs, char const *fmt,...) CC_HINT(format(printf
static struct hashtable * build_hash_table(char const *file, int nfields, int keyfield, int islist, int tablesize, int ignorenis, char delimiter)
enum rlm_rcodes rlm_rcode_t
Return codes indicating the result of the module call.
static void addresult(TALLOC_CTX *ctx, rlm_passwd_t *inst, REQUEST *request, VALUE_PAIR **vps, struct mypasswd *pw, char when, char const *listname)
VALUE_PAIR * fr_pair_find_by_da(VALUE_PAIR *head, fr_dict_attr_t const *da, int8_t tag)
Find the pair with the matching DAs.
uint64_t magic
Used to validate module struct.
#define FR_CONF_OFFSET(_n, _t, _s, _f)
fr_dict_attr_t const * keyattr
6 methods index for postproxy section.
#define PW_TYPE_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
8 methods index for recvcoa section.
int main(int argc, char *argv[])
9 methods index for sendcoa section.
String of printable characters.
static int mod_detach(void *instance)
1 methods index for authorize section.
static struct mypasswd * mypasswd_malloc(char const *buffer, int nfields, size_t *len)
char * talloc_typed_strdup(void const *t, char const *p)
Call talloc strdup, setting the type on the new chunk correctly.
VALUE_PAIR * fr_pair_make(TALLOC_CTX *ctx, VALUE_PAIR **vps, char const *attribute, char const *value, FR_TOKEN op)
Create a VALUE_PAIR from ASCII strings.
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_t *dict, char const *attr)
Locate a fr_dict_attr_t by its name.