326
327
*************************************************************************/
327
328
int sql_userparse(VALUE_PAIR ** first_pair, SQL_ROW row, int querymode)
330
330
VALUE_PAIR *pair, *check;
334
LRAD_TOKEN xlat, pairmode = T_EOL;
332
char buf[MAX_STRING_LEN];
334
LRAD_TOKEN token, operator = T_EOL;
336
if ((attr = dict_attrbyname(row[2])) == (DICT_ATTR *) NULL) {
337
radlog(L_ERR | L_CONS, "rlm_sql: unknown attribute %s",
337
* Verify the 'Attribute' field
339
if (row[2] == NULL || row[2][0] == '\0') {
340
radlog(L_ERR, "rlm_sql: The 'Attribute' field is empty or NULL, skipping the entire row.");
342
if (row[4] != NULL && strlen(row[4]) > 0) {
345
* Verify the 'op' field
347
if (row[4] != NULL && row[4][0] != '\0') {
344
pairmode = gettoken(&ptr, buf, sizeof(buf));
349
operator = gettoken(&ptr, buf, sizeof(buf));
351
if (operator <= T_EOL) {
347
* 'op' fields of NULL are a plague, and a bane on the
348
* existence of mankind.
353
* Complain about empty or invalid 'op' field
355
operator = T_OP_CMP_EQ;
350
356
radlog(L_ERR, "rlm_sql: The 'op' field for attribute '%s = %s' is NULL, or non-existent.", row[2], row[3]);
351
357
radlog(L_ERR, "rlm_sql: You MUST FIX THIS if you want the configuration to behave as you expect.");
353
if (pairmode <= T_EOL) pairmode = T_OP_CMP_EQ;
356
* If attribute is already there, skip it because we checked usercheck first
357
* and we want user settings to over ride group settings
361
* The 'Value' field may be empty or NULL
359
if (pairmode != T_OP_ADD && (check = pairfind(*first_pair, attr->attr)) != NULL &&
361
attr->type != PW_TYPE_ABINARY &&
363
querymode == PW_VP_GROUPDATA)
367
365
* If we have a new-style quoted string, where the
368
366
* *entire* string is quoted, do xlat's.
370
if (((row[3][0] == '\'') ||
371
(row[3][0] == '`') ||
372
(row[3][0] == '"')) &&
373
(row[3][0] == row[3][strlen(row[3])-1])) {
368
if (row[3] != NULL &&
369
((row[3][0] == '\'') || (row[3][0] == '`') || (row[3][0] == '"')) &&
370
(row[3][0] == row[3][strlen(row[3])-1])) {
376
xlat = gettoken(&ptr, value, sizeof(value));
372
token = gettoken(&value, buf, sizeof(buf));
379
* Make the full pair now.
375
* Take the unquoted string.
382
pair = pairmake(row[2], row[3], pairmode);
385
377
case T_SINGLE_QUOTED_STRING:
386
378
case T_DOUBLE_QUOTED_STRING:
387
pair = pairmake(row[2], value, pairmode);
391
383
* Mark the pair to be allocated later.
393
385
case T_BACK_QUOTED_STRING:
394
pair = pairmake(row[2], NULL, pairmode);
396
pair->flags.do_xlat = 1;
397
strNcpy(pair->strvalue, value, sizeof(pair->strvalue));
391
* Keep the original string.
403
* String starts and ends differently. Take it literally
405
pair = pairmake(row[2], row[3], pairmode);
402
pair = pairmake(row[2], value, operator);
404
radlog(L_ERR, "rlm_sql: Failed to create the pair: %s", librad_errstr);
408
pair->flags.do_xlat = 1;
409
strNcpy(pair->strvalue, buf, sizeof(pair->strvalue));
414
* If attribute is already there, skip it because we
415
* checked usercheck first and we want user settings to
416
* override group settings
418
if (operator != T_OP_ADD && (check = pairfind(*first_pair, pair->attribute)) != NULL &&
420
pair->type != PW_TYPE_ABINARY &&
422
querymode == PW_VP_GROUPDATA) {
428
* Add the pair into the packet
407
430
pairadd(first_pair, pair);