~ubuntu-branches/ubuntu/dapper/freeradius/dapper-updates

« back to all changes in this revision

Viewing changes to src/modules/rlm_dbm/rlm_dbm.c

  • Committer: Bazaar Package Importer
  • Author(s): Paul Hampson
  • Date: 2004-12-29 20:19:42 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041229201942-uj2e95la965uthc7
Tags: 1.0.1-2
* freeradius-dialupadmin Suggests php4-mysql | php4-pgsql
   Closes: #279419
* Added a two-second pause to restart in init.d script
   Closes: #262635
* FreeRADIUS module packages now depend on the same source
  version of the main FreeRADIUS package.
   Closes: #284353
* FreeRADIUS-dialupadmin's default paths in admin.conf are
  now correct.
   Closes: #280942
* FreeRADIUS-dialupadmin's help.php3 can now find README.
   Closes: #280941
* Fixes stolen from 1.0.2 CVS:
  - Bug fix to make udpfromto code work
  - radrelay shouldn't dump core if it can't read a VP from the
    detail file.
  - Only initialize the random pool once.
  - In rlm_sql, don't escape characters twice.
  - In rlm_ldap, only claim Auth-Type if a plain text password is present.
  - Locking fixes in threading code
  - Fix building on gcc-4.0 by not trying to access static auth_port from
    other files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * rlm_dbm.c authorize:    authorize using ndbm database
3
3
 *
4
 
 * Version:     $Id: rlm_dbm.c,v 1.6.2.1 2003/09/12 19:18:03 phampson Exp $
 
4
 * Version:     $Id: rlm_dbm.c,v 1.9 2004/02/26 19:04:28 aland Exp $
5
5
 *
6
6
 *   This program is free software; you can redistribute it and/or modify
7
7
 *   it under the terms of the GNU General Public License as published by
45
45
#       include "sandymod.h"
46
46
#endif
47
47
 
48
 
static const char rcsid[] = "$Id: rlm_dbm.c,v 1.6.2.1 2003/09/12 19:18:03 phampson Exp $";
 
48
static const char rcsid[] = "$Id: rlm_dbm.c,v 1.9 2004/02/26 19:04:28 aland Exp $";
49
49
 
50
50
#define MYDBM   DBM
51
51
#define get_user_content dbm_fetch
61
61
#ifdef SANDY_MOD
62
62
        char    *dms_servers;
63
63
        char    *ducpd_servers;
64
 
#endif 
 
64
#endif
65
65
        char    *userfile;
66
66
        int     findmod;
67
67
} rlm_dbm_t;
73
73
 
74
74
 
75
75
static CONF_PARSER module_config[] = {
76
 
        { "usersfile",     PW_TYPE_STRING_PTR,offsetof(struct rlm_dbm_t,userfile), 
 
76
        { "usersfile",     PW_TYPE_STRING_PTR,offsetof(struct rlm_dbm_t,userfile),
77
77
                NULL, "/etc/uf" },
78
78
        { NULL, -1, 0, NULL, NULL }
79
79
};
80
80
 
81
81
static void sm_user_list_wipe (SM_USER_ENTRY **ue) {
82
 
        
 
82
 
83
83
        SM_USER_ENTRY * pue, *nue;
84
 
        
 
84
 
85
85
        if ( ! *ue ) return ;
86
86
        pue = *ue;
87
 
        
 
87
 
88
88
        while ( pue != NULL ) {
89
89
                nue = pue -> next;
90
90
                DEBUG2("Remove %s from user list", pue -> username);
91
91
                free(pue -> username);
92
92
                free(pue);
93
 
                pue = nue; 
 
93
                pue = nue;
94
94
        }
95
95
        *ue = NULL;
96
96
}
103
103
 */
104
104
 
105
105
static int sm_user_list_add(SM_USER_ENTRY **ue, const char *un) {
106
 
        
 
106
 
107
107
        while( *ue ) {
108
 
                if ( strcmp( (*ue) -> username, un) == 0 ) return 1; 
 
108
                if ( strcmp( (*ue) -> username, un) == 0 ) return 1;
109
109
                ue = & ((*ue) -> next);
110
110
        }
111
111
        *ue = malloc(sizeof(SM_USER_ENTRY));
143
143
 *  pdb - ndbm handler
144
144
 *  username - user name from request
145
145
 *  request - pair originated from the nas
146
 
 *  mode - search mode SM_SM_ACCUM - accumulative search mode 
 
146
 *  mode - search mode SM_SM_ACCUM - accumulative search mode
147
147
 *  out-parameters:
148
148
 *  in-out:
149
149
 *  parsed_users - list of parsed user names for loop removal
150
150
 */
151
 
 
 
151
 
152
152
static int sm_parse_user(DBM *pdb, const char * username, VALUE_PAIR const* request, VALUE_PAIR **config,
153
153
                VALUE_PAIR **reply, SM_USER_ENTRY **ulist)
154
154
{
157
157
        VALUE_PAIR *vp = NULL,* tmp_config = NULL, *tmp_reply = NULL, *nu_reply = NULL;
158
158
        VALUE_PAIR *join_attr;
159
159
        char    *ch,*beg;
160
 
        
161
 
        int     parse_state = SMP_PATTERN; 
 
160
 
 
161
        int     parse_state = SMP_PATTERN;
162
162
        int     continue_search = 1;
163
 
        
 
163
 
164
164
        /* check for loop */
165
 
        
 
165
 
166
166
        DEBUG2("sm_parse_user.c: check for loops");
167
167
 
168
168
        if ( (retcod = sm_user_list_add(ulist,username) ) ) {
169
169
                if ( retcod < 0 ) radlog(L_ERR,"rlm_dbm: Couldn't allocate memory");
170
170
                        else radlog(L_ERR,"rlm_dbm: Invalid configuration: loop detected");
171
 
                return RLM_MODULE_FAIL;  
 
171
                return RLM_MODULE_FAIL;
172
172
        }
173
173
 
174
174
        /* retrieve user content */
175
 
        
 
175
 
176
176
        k.dptr  = username;
177
177
        k.dsize = strlen(username) + 1 ; /* username stored with '\0' */
178
 
        
 
178
 
179
179
        d = dbm_fetch(pdb, k);
180
180
        if ( d.dptr == NULL ) {
181
181
                 DEBUG2("rlm_dbm: User <%s> not foud in database\n",username);
182
182
                 return RLM_MODULE_NOTFOUND;
183
183
        }
184
 
        
 
184
 
185
185
        ch = d.dptr;
186
186
        ch [ d.dsize - 1 ] = '\0'; /* should be closed by 0 */
187
 
        
 
187
 
188
188
        DEBUG2("sm_parse_user: start parsing: user: %s", username);
189
 
        
 
189
 
190
190
        /*  start parse content */
191
191
        while ( parse_state != SMP_ERROR && *ch && continue_search ) {
192
192
 
193
193
                beg = ch;
194
194
 
195
195
                while( *ch && *ch != '\n') ch++ ;
196
 
                
 
196
 
197
197
                if ( *ch == '\n' ) { *ch = 0; ch++; }
198
198
 
199
 
                DEBUG2("parse buffer: <<%s>>\n",beg); 
200
 
                
 
199
                DEBUG2("parse buffer: <<%s>>\n",beg);
 
200
 
201
201
                retcod = userparse(beg,&vp);
202
202
                if ( retcod == T_INVALID ) librad_perror("parse error ");
203
 
                
 
203
 
204
204
                switch ( retcod ) {
205
205
                        case T_COMMA: break; /* continue parse the current list */
206
 
                        case T_EOL:     DEBUG2("rlm_dbm: recod parsed\n"); /* vp contains full pair list */ 
 
206
                        case T_EOL:     DEBUG2("rlm_dbm: recod parsed\n"); /* vp contains full pair list */
207
207
                                        if ( parse_state == SMP_PATTERN ) { /* pattern line found */
208
208
                                                DEBUG2("process pattern");
209
209
                                                /* check pattern against request */
214
214
                                                        parse_state = SMP_REPLY; /* look for reply */
215
215
                                                } else  {
216
216
                                                          /* skip reply */
217
 
                                                        DEBUG2("rlm_dbm: patern not matched, reply skiped");  
 
217
                                                        DEBUG2("rlm_dbm: patern not matched, reply skiped");
218
218
                                                        pairfree(&vp);
219
219
                                                        while ( *ch && *ch !='\n' ) ch++;
220
220
                                                        if ( *ch == '\n' ) ch++;
223
223
                                                /* look for join-attribute */
224
224
                                                DEBUG2("rlm_dbm: Reply found");
225
225
                                                join_attr = vp;
226
 
                                                while( (join_attr = pairfind(join_attr,SM_JOIN_ATTR) ) != NULL ) { 
 
226
                                                while( (join_attr = pairfind(join_attr,SM_JOIN_ATTR) ) != NULL ) {
227
227
                                                        DEBUG2("rlm_dbm: Proccess nested record: username %s",
228
228
                                                                (char *)join_attr->strvalue);
229
229
                                                        /* res =  RLM_MODULE_NOTFOUND; */
230
 
                                                        res =  sm_parse_user(pdb, (char *)join_attr->strvalue, request, &tmp_config, 
 
230
                                                        res =  sm_parse_user(pdb, (char *)join_attr->strvalue, request, &tmp_config,
231
231
                                                                        &nu_reply, ulist);
232
232
                                                        DEBUG("rlm_dbm: recived: %d\n",res);
233
233
                                                        switch ( res ) {
257
257
                                                pairfree(&vp);
258
258
                                                pairfree(&nu_reply);                                    }
259
259
                                        break;
260
 
                        default:        /* we do not wait that !!!! */ 
 
260
                        default:        /* we do not wait that !!!! */
261
261
                                        parse_state = SMP_ERROR;
262
262
                                        DEBUG2("rlm_dbm: Unknown token: %d\n",retcod);
263
263
                                        break;
264
264
                }
265
 
                
 
265
 
266
266
        }
267
267
        if ( parse_state == SMP_PATTERN  ) {
268
 
                pairmove(config,&tmp_config); 
 
268
                pairmove(config,&tmp_config);
269
269
                pairfree(&tmp_config);
270
270
                pairmove(reply,&tmp_reply);
271
271
                pairfree(&tmp_reply);
280
280
        return found;
281
281
}
282
282
 
283
 
static int sm_postprocessor(VALUE_PAIR **reply) {
 
283
static int sm_postprocessor(VALUE_PAIR **reply UNUSED) {
284
284
        return 0;
285
 
 
285
}
286
286
 
287
287
static int rlm_dbm_instantiate(CONF_SECTION *conf, void **instance) {
288
288
        struct rlm_dbm_t *inst;
289
 
        
 
289
 
290
290
        inst = rad_malloc(sizeof(rlm_dbm_t));
291
291
        if (!inst) {
292
292
                return -1;
294
294
        memset(inst, 0, sizeof(*inst));
295
295
 
296
296
        if (cf_section_parse(conf, inst, module_config) < 0) {
297
 
                free(inst);      
 
297
                free(inst);
298
298
                return -1;
299
299
        }
300
300
        *instance = inst;
310
310
        int             found = 0;
311
311
        const char      *name;
312
312
        SM_USER_ENTRY   *ulist = NULL;
313
 
        DBM             *pdb; 
 
313
        DBM             *pdb;
314
314
 
315
315
        struct rlm_dbm_t *inst = instance;
316
316
 
317
317
        VALUE_PAIR **check_pairs, **reply_pairs;
318
 
                                
 
318
 
319
319
        request_pairs = request->packet->vps;
320
320
        check_pairs = &request->config_items;
321
321
        reply_pairs = &request->reply->vps;
322
 
        
 
322
 
323
323
        /*
324
324
         *      Grab the canonical user name.
325
325
         */
326
326
        namepair = request->username;
327
327
        name = namepair ? (char *) namepair->strvalue : "NONE";
328
 
        
 
328
 
329
329
        DEBUG2("rlm_dbm: try open database file: %s\n",inst -> userfile);
330
330
 
331
331
        /* open database */
335
335
                if ( found == RLM_MODULE_NOTFOUND ) {
336
336
                  sm_user_list_wipe(&ulist);
337
337
                  found = sm_parse_user(pdb, "DEFAULT", request_pairs, &check_tmp, &reply_tmp, &ulist);
338
 
                }       
 
338
                }
339
339
                dbm_close(pdb);
340
 
        } else { 
 
340
        } else {
341
341
                found = RLM_MODULE_FAIL;
342
342
                DEBUG2("rlm_dbm: Cannot open database file: %s\n",
343
343
                       strerror(errno));
353
353
        sm_user_list_wipe(&ulist);
354
354
        pairfree(&reply_tmp);
355
355
        pairfree(&check_tmp);
356
 
        
 
356
 
357
357
        return found;
358
358
}
359
359
 
367
367
 
368
368
 
369
369
/* globally exported name */
370
 
module_t rlm_dbm = {   
 
370
module_t rlm_dbm = {
371
371
        "dbm",
372
372
        0,                              /* type: reserved */
373
373
        NULL,                           /* initialization */