Build courier-authlib 0.59.3-1hcoop1.
[hcoop/debian/courier-authlib.git] / authoption.c
1 /*
2 ** Copyright 2002 Double Precision, Inc. See COPYING for
3 ** distribution information.
4 */
5
6 #if HAVE_CONFIG_H
7 #include "courier_auth_config.h"
8 #endif
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <errno.h>
13 #include <pwd.h>
14 #if HAVE_UNISTD_H
15 #include <unistd.h>
16 #endif
17
18 #include "auth.h"
19
20 static const char rcsid[]="$Id: authoption.c,v 1.3 2004/11/10 00:42:04 mrsam Exp $";
21
22
23 int auth_getoptionenvint(const char *keyword)
24 {
25 char *p = auth_getoptionenv(keyword);
26 int i;
27
28 if (!p) return 0;
29
30 i = atoi(p);
31 free(p);
32 return i;
33 }
34
35 char *auth_getoptionenv(const char *keyword)
36 {
37 return auth_getoption(getenv("OPTIONS"), keyword);
38 }
39
40 char *auth_getoption(const char *options, const char *keyword)
41 {
42 size_t keyword_l=strlen(keyword);
43 char *p;
44
45 while (options)
46 {
47 if (strncmp(options, keyword, keyword_l) == 0)
48 {
49 if (options[keyword_l] == 0 ||
50 options[keyword_l] == ',')
51 return strdup("");
52
53 if (options[keyword_l] == '=')
54 {
55 options += keyword_l;
56 ++options;
57
58 for (keyword_l=0;
59 options[keyword_l] &&
60 options[keyword_l] != ',';
61 ++keyword_l)
62 ;
63
64 if (!(p=malloc(keyword_l+1)))
65 return NULL;
66 memcpy(p, options, keyword_l);
67 p[keyword_l]=0;
68 return p;
69 }
70 }
71
72 options=strchr(options, ',');
73 if (options)
74 ++options;
75 }
76 errno=ENOENT;
77 return NULL;
78 }