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

« back to all changes in this revision

Viewing changes to src/modules/rlm_acct_unique/rlm_acct_unique.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:
33
33
 */
34
34
#define  BUFFERLEN  4096
35
35
 
36
 
static const char rcsid[] = "$Id: rlm_acct_unique.c,v 1.27.2.1 2003/09/12 19:18:03 phampson Exp $";
 
36
static const char rcsid[] = "$Id: rlm_acct_unique.c,v 1.29 2004/02/26 19:04:27 aland Exp $";
37
37
 
38
38
typedef struct rlm_acct_unique_list_t {
39
39
        DICT_ATTR                     *dattr;
42
42
 
43
43
typedef struct rlm_acct_unique_t {
44
44
        char                    *key;
45
 
        rlm_acct_unique_list_t *head;           
 
45
        rlm_acct_unique_list_t *head;
46
46
} rlm_acct_unique_t;
47
47
 
48
48
static CONF_PARSER module_config[] = {
55
55
 */
56
56
static void unique_add_attr(rlm_acct_unique_t *inst, DICT_ATTR *dattr)
57
57
{
58
 
        rlm_acct_unique_list_t  *new;           
59
 
        
 
58
        rlm_acct_unique_list_t  *new;
 
59
 
60
60
        new = rad_malloc(sizeof(*new));
61
61
        memset(new, 0, sizeof(*new));
62
62
 
74
74
{
75
75
        char *ptr, *prev, *keyptr;
76
76
        DICT_ATTR *a;
77
 
        
 
77
 
78
78
        keyptr = key;
79
79
        ptr = key;
80
80
        prev = key;
81
 
        
 
81
 
82
82
        /* Let's remove spaces in the string */
83
83
        rad_rmspace(key);
84
 
        
 
84
 
85
85
        ptr = key;
86
86
        while(ptr) {
87
87
                switch(*ptr) {
107
107
                        continue;
108
108
                        break;
109
109
                }
110
 
                ptr++;  
111
 
        }       
112
 
        
 
110
                ptr++;
 
111
        }
 
112
 
113
113
        return 0;
114
114
}
115
115
 
140
140
         */
141
141
        inst = rad_malloc(sizeof(*inst));
142
142
        memset(inst, 0, sizeof(*inst));
143
 
        
 
143
 
144
144
        if (cf_section_parse(conf, inst, module_config) < 0) {
145
145
                free(inst);
146
146
                return -1;
147
147
        }
148
148
 
149
 
        /* 
150
 
         *      Check to see if 'key' has something in it 
151
 
         */     
 
149
        /*
 
150
         *      Check to see if 'key' has something in it
 
151
         */
152
152
        if (!inst->key) {
153
153
                radlog(L_ERR,"rlm_acct_unique: Cannot find value for 'key' in configuration.");
154
154
                free(inst);
155
155
                return -1;
156
156
        }
157
157
 
158
 
        /* 
 
158
        /*
159
159
         * Go thru the list of keys and build attr_list;
160
 
         */     
 
160
         */
161
161
        if (unique_parse_key(inst, inst->key) < 0) {
162
162
                unique_detach(inst); /* clean up memory */
163
163
                return -1;
182
182
        int length, left;
183
183
        rlm_acct_unique_t *inst = instance;
184
184
        rlm_acct_unique_list_t *cur;
185
 
  
 
185
 
186
186
        /* initialize variables */
187
187
        p = buffer;
188
188
        left = BUFFERLEN;
189
189
        length = 0;
190
190
        cur = inst->head;
191
 
        
 
191
 
192
192
        /*
193
193
         *  A unique ID already exists: don't do anything.
194
194
         */
196
196
        if (vp) {
197
197
                return RLM_MODULE_NOOP;
198
198
        }
199
 
        
 
199
 
200
200
        /* loop over items to create unique identifiers */
201
201
        while (cur) {
202
202
                vp = pairfind(request->packet->vps, cur->dattr->attr);
210
210
                cur = cur->next;
211
211
        }
212
212
        buffer[BUFFERLEN-left-1] = '\0';
213
 
        
 
213
 
214
214
        DEBUG2("rlm_acct_unique: Hashing '%s'", buffer);
215
215
        /* calculate a 'unique' string based on the above information */
216
216
        librad_md5_calc(md5_buf, (u_char *)buffer, (p - buffer));
217
217
        sprintf(buffer, "%02x%02x%02x%02x%02x%02x%02x%02x",
218
218
                md5_buf[0], md5_buf[1], md5_buf[2], md5_buf[3],
219
219
                md5_buf[4], md5_buf[5], md5_buf[6], md5_buf[7]);
220
 
        
 
220
 
221
221
        DEBUG2("rlm_acct_unique: Acct-Unique-Session-ID = \"%s\".", buffer);
222
 
        
 
222
 
223
223
        vp = pairmake("Acct-Unique-Session-Id", buffer, 0);
224
224
        if (!vp) {
225
225
                radlog(L_ERR, "%s", librad_errstr);
226
226
                return RLM_MODULE_FAIL;
227
227
        }
228
 
        
 
228
 
229
229
        /* add the (hopefully) unique session ID to the packet */
230
230
        pairadd(&request->packet->vps, vp);
231
 
        
 
231
 
232
232
        return RLM_MODULE_OK;
233
233
}
234
234