Commit | Line | Data |
---|---|---|
d9898ee8 | 1 | /* |
8d138742 | 2 | ** Copyright 2002-2009 Double Precision, Inc. See COPYING for |
d9898ee8 | 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 | ||
d9898ee8 | 20 | |
21 | ||
22 | int auth_getoptionenvint(const char *keyword) | |
23 | { | |
24 | char *p = auth_getoptionenv(keyword); | |
25 | int i; | |
26 | ||
27 | if (!p) return 0; | |
28 | ||
29 | i = atoi(p); | |
8d138742 CE |
30 | |
31 | if (i == 0 && strchr("tTyY", *p)) | |
32 | i=1; /* Convert 'true', 'TRUE', 'yes', 'YES' to 1 */ | |
d9898ee8 | 33 | free(p); |
34 | return i; | |
35 | } | |
36 | ||
37 | char *auth_getoptionenv(const char *keyword) | |
38 | { | |
39 | return auth_getoption(getenv("OPTIONS"), keyword); | |
40 | } | |
41 | ||
42 | char *auth_getoption(const char *options, const char *keyword) | |
43 | { | |
44 | size_t keyword_l=strlen(keyword); | |
45 | char *p; | |
46 | ||
47 | while (options) | |
48 | { | |
49 | if (strncmp(options, keyword, keyword_l) == 0) | |
50 | { | |
51 | if (options[keyword_l] == 0 || | |
52 | options[keyword_l] == ',') | |
53 | return strdup(""); | |
54 | ||
55 | if (options[keyword_l] == '=') | |
56 | { | |
57 | options += keyword_l; | |
58 | ++options; | |
59 | ||
60 | for (keyword_l=0; | |
61 | options[keyword_l] && | |
62 | options[keyword_l] != ','; | |
63 | ++keyword_l) | |
64 | ; | |
65 | ||
66 | if (!(p=malloc(keyword_l+1))) | |
67 | return NULL; | |
68 | memcpy(p, options, keyword_l); | |
69 | p[keyword_l]=0; | |
70 | return p; | |
71 | } | |
72 | } | |
73 | ||
74 | options=strchr(options, ','); | |
75 | if (options) | |
76 | ++options; | |
77 | } | |
78 | errno=ENOENT; | |
79 | return NULL; | |
80 | } |