Commit c119cfbf c119cfbf30de4e81b5a8f1eb60aef477566277ae by Sergey Poznyakoff

* auth/ldap.c (_construct_attr_array): Use mu_vartab_* to expand

filter.
* imap4d/preauth.c: Fix misleading comment.
* mailbox/vartab.c (mu_vartab_expand): Support old prefix (%) for
single-character variables.
1 parent 6aa04988
1 2007-12-09 Sergey Poznyakoff <gray@gnu.org.ua>
2
3 * auth/ldap.c (_construct_attr_array): Use mu_vartab_* to expand
4 filter.
5 * imap4d/preauth.c: Fix misleading comment.
6 * mailbox/vartab.c (mu_vartab_expand): Support old prefix (%) for
7 single-character variables.
8
1 2007-12-07 Sergey Poznyakoff <gray@gnu.org.ua> 9 2007-12-07 Sergey Poznyakoff <gray@gnu.org.ua>
2 10
3 * NEWS, TODO: Update. 11 * NEWS, TODO: Update.
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
42 #include "mailutils/md5.h" 42 #include "mailutils/md5.h"
43 #include "mailutils/sha1.h" 43 #include "mailutils/sha1.h"
44 #include "mailutils/ldap.h" 44 #include "mailutils/ldap.h"
45 #include "mailutils/vartab.h"
45 46
46 #include <ldap.h> 47 #include <ldap.h>
47 #include <lber.h> 48 #include <lber.h>
...@@ -351,85 +352,6 @@ _mu_ldap_unbind (LDAP *ld) ...@@ -351,85 +352,6 @@ _mu_ldap_unbind (LDAP *ld)
351 } 352 }
352 } 353 }
353 354
354 /* FIXME: 1. Duplicated in radius.c
355 2. Does not escape arguments
356 */
357 static char *
358 _expand_query (const char *query, const char *ustr)
359 {
360 char *p, *q, *res;
361 int len;
362
363 if (!query)
364 return NULL;
365
366 /* Compute resulting query length */
367 for (len = 0, p = (char *) query; *p; )
368 {
369 if (*p == '%')
370 {
371 if (p[1] == 'u')
372 {
373 len += ustr ? strlen (ustr) : 2;
374 p += 2;
375 }
376 else if (p[1] == '%')
377 {
378 len++;
379 p += 2;
380 }
381 else
382 {
383 len++;
384 p++;
385 }
386 }
387 else
388 {
389 len++;
390 p++;
391 }
392 }
393
394 res = malloc (len + 1);
395 if (!res)
396 return res;
397
398 for (p = (char *) query, q = res; *p; )
399 {
400 if (*p == '%')
401 {
402 switch (*++p)
403 {
404 case 'u':
405 if (ustr)
406 {
407 strcpy (q, ustr);
408 q += strlen (q);
409 }
410 else
411 {
412 *q++ = '%';
413 *q++ = 'u';
414 }
415 p++;
416 break;
417
418 case '%':
419 *q++ = *p++;
420 break;
421
422 default:
423 *q++ = *p++;
424 }
425 }
426 else
427 *q++ = *p++;
428 }
429 *q = 0;
430 return res;
431 }
432
433 static int 355 static int
434 _construct_attr_array (size_t *pargc, char ***pargv) 356 _construct_attr_array (size_t *pargc, char ***pargv)
435 { 357 {
...@@ -586,12 +508,17 @@ _mu_ldap_search (LDAP *ld, const char *filter_pat, const char *key, ...@@ -586,12 +508,17 @@ _mu_ldap_search (LDAP *ld, const char *filter_pat, const char *key,
586 size_t nattrs; 508 size_t nattrs;
587 LDAPMessage *res, *msg; 509 LDAPMessage *res, *msg;
588 ber_int_t msgid; 510 ber_int_t msgid;
589 511 mu_vartab_t vtab;
512
590 rc = _construct_attr_array (&nattrs, &attrs); 513 rc = _construct_attr_array (&nattrs, &attrs);
591 if (rc) 514 if (rc)
592 return rc; 515 return rc;
593 filter = _expand_query (filter_pat, key); 516
594 if (!filter) 517 mu_vartab_create (&vtab);
518 mu_vartab_define (vtab, "user", key, 1);
519 rc = mu_vartab_expand (vtab, filter_pat, &filter);
520 mu_vartab_destroy (&vtab);
521 if (rc)
595 { 522 {
596 mu_argcv_free (nattrs, attrs); 523 mu_argcv_free (nattrs, attrs);
597 return ENOMEM; 524 return ENOMEM;
......
...@@ -40,7 +40,7 @@ do_preauth_stdio (struct sockaddr_in *pcs) ...@@ -40,7 +40,7 @@ do_preauth_stdio (struct sockaddr_in *pcs)
40 40
41 "%*[^:]: USERID :%*[^:]:%s" 41 "%*[^:]: USERID :%*[^:]:%s"
42 42
43 returns a mallocked copy of the %s part. Otherwise, return NULL. */ 43 return a pointer to the %s part. Otherwise, return NULL. */
44 44
45 static char * 45 static char *
46 ident_extract_username (char *reply) 46 ident_extract_username (char *reply)
......
...@@ -289,10 +289,42 @@ mu_vartab_expand (mu_vartab_t vt, const char *str, char **pres) ...@@ -289,10 +289,42 @@ mu_vartab_expand (mu_vartab_t vt, const char *str, char **pres)
289 } 289 }
290 else if (rc == MU_ERR_NOENT) 290 else if (rc == MU_ERR_NOENT)
291 p++; 291 p++;
292 else
293 return rc;
292 } 294 }
293 break; 295 break;
294 } 296 }
295 } 297 }
298 else if (*p == '%')
299 {
300 /* allow `%' as prefix for single-character entities, for
301 compatibility with v. prior to 1.2.91 */
302 if (*++p == '%')
303 {
304 mu_stream_sequential_write (vt->stream, str, p - str);
305 str = p + 1;
306 p = str + 1;
307 }
308 else
309 {
310 char *name = copy_name (vt, p, 1);
311 const char *pvalue;
312 rc = mu_vartab_getvar (vt, name, &pvalue);
313 if (rc == 0)
314 {
315 mu_stream_sequential_write (vt->stream, str,
316 p - str - 1);
317 mu_stream_sequential_write (vt->stream, pvalue,
318 strlen (pvalue));
319 str = p + 1;
320 p = str + 1;
321 }
322 else if (rc == MU_ERR_NOENT)
323 p++;
324 else
325 return rc;
326 }
327 }
296 else 328 else
297 p++; 329 p++;
298 } 330 }
......