]> git.sur5r.net Git - openldap/blob - libraries/libldap/options.c
b52e95cc7866cd9e9e21b39f1a82359fc757e376
[openldap] / libraries / libldap / options.c
1 #include "portable.h"
2
3 #include <stdio.h>
4 #include <stdlib.h>
5
6 #include <ac/socket.h>
7 #include <ac/string.h>
8
9 #include "ldap-int.h"
10
11 int
12 ldap_get_option(
13         LDAP    *ld,
14         int             option,
15         void    *outvalue)
16 {
17         struct ldapoptions *lo;
18
19         if(!openldap_ldap_initialized) {
20                 openldap_ldap_initialize();
21         }
22
23         if(outvalue == NULL) {
24                 /* no place to get to */
25                 return -1;
26         }
27
28         if(ld == NULL) {
29                 lo = &openldap_ldap_global_options;
30         } else {
31                 lo = &ld->ld_options;
32         }
33
34         switch(option) {
35         case LDAP_OPT_API_INFO: {
36                         struct ldapapiinfo *info = (struct ldapapiinfo *) outvalue;
37
38                         if(info == NULL) {
39                                 /* outvalue must point to an apiinfo structure */
40                                 return -1;
41                         }
42
43                         if(info->ldapai_info_version != LDAP_API_INFO_VERSION) {
44                                 /* api info version mismatch */
45                                 info->ldapai_info_version = LDAP_API_INFO_VERSION;
46                                 return -1;
47                         }
48
49                         info->ldapai_api_version = LDAP_API_VERSION;
50                         info->ldapai_api_version = LDAP_API_VERSION;
51                         info->ldapai_protocol_version = LDAP_VERSION_MAX;
52                         info->ldapai_extensions = NULL;
53                         info->ldapai_vendor_name = strdup(LDAP_VENDOR_NAME);
54                         info->ldapai_vendor_version = LDAP_VENDOR_VERSION;
55
56                         return 0;
57                 } break;
58
59         case LDAP_OPT_DESC:
60                 if(ld == NULL) {
61                         /* bad param */
62                         break;
63                 } 
64
65                 * (int *) outvalue = ld->ld_sb.sb_sd;
66                 return 0;
67
68         case LDAP_OPT_DEREF:
69                 * (int *) outvalue = lo->ldo_deref;
70                 return 0;
71
72         case LDAP_OPT_SIZELIMIT:
73                 * (int *) outvalue = lo->ldo_sizelimit;
74                 return 0;
75
76         case LDAP_OPT_TIMELIMIT:
77                 * (int *) outvalue = lo->ldo_timelimit;
78                 return 0;
79
80         case LDAP_OPT_REFERRALS:
81                 * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_REFERRALS);
82                 return 0;
83                 
84         case LDAP_OPT_RESTART:
85                 * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_RESTART);
86                 return 0;
87
88         case LDAP_OPT_DNS:      /* LDAPv2 */
89                 * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_DNS);
90                 return 0;
91
92         case LDAP_OPT_PROTOCOL_VERSION:
93                 if(ld == NULL) {
94                         /* bad param */
95                         break;
96                 } 
97
98                 * (int *) outvalue = ld->ld_version;
99                 return 0;
100
101         case LDAP_OPT_SERVER_CONTROLS:
102         case LDAP_OPT_CLIENT_CONTROLS:
103                 /* not yet supported */
104                 break;
105
106         case LDAP_OPT_HOST_NAME:
107                 if(ld == NULL) {
108                         /* bad param */
109                         break;
110                 } 
111                 * (char **) outvalue = ld->ld_host;
112                 return 0;
113
114         case LDAP_OPT_ERROR_NUMBER:
115                 if(ld == NULL) {
116                         /* bad param */
117                         break;
118                 } 
119                 * (int *) outvalue = ld->ld_errno;
120                 return 0;
121
122         case LDAP_OPT_ERROR_STRING:
123                 /* not yet supported */
124                 if(ld == NULL) {
125                         /* bad param */
126                         break;
127                 } 
128                 break;
129
130         default:
131                 /* bad param */
132                 break;
133         }
134
135         return -1;
136 }
137
138 int
139 ldap_set_option(
140         LDAP    *ld,
141         int             option,
142         void    *invalue)
143 {
144         struct ldapoptions *lo;
145
146         if(!openldap_ldap_initialized) {
147                 openldap_ldap_initialize();
148         }
149
150         if(invalue == NULL) {
151                 /* no place to set from */
152                 return -1;
153         }
154
155         if(ld == NULL) {
156                 lo = &openldap_ldap_global_options;
157         } else {
158                 lo = &ld->ld_options;
159         }
160
161         switch(option) {
162         case LDAP_OPT_API_INFO:
163         case LDAP_OPT_DESC:
164                 /* READ ONLY */
165                 break;
166
167         case LDAP_OPT_DEREF:
168                 lo->ldo_deref = * (int *) invalue;
169                 return 0;
170
171         case LDAP_OPT_SIZELIMIT:
172                 lo->ldo_sizelimit = * (int *) invalue;
173                 return 0;
174
175         case LDAP_OPT_TIMELIMIT:
176                 lo->ldo_timelimit = * (int *) invalue;
177                 return 0;
178
179         case LDAP_OPT_REFERRALS:
180                 if((int) invalue == (int) LDAP_OPT_ON) {
181                         LDAP_BOOL_SET(lo, LDAP_BOOL_REFERRALS);
182                 } else {
183                         LDAP_BOOL_CLR(lo, LDAP_BOOL_REFERRALS);
184                 }
185                 return 0;
186
187         case LDAP_OPT_RESTART:
188                 if((int) invalue == (int) LDAP_OPT_ON) {
189                         LDAP_BOOL_SET(lo, LDAP_BOOL_RESTART);
190                 } else {
191                         LDAP_BOOL_CLR(lo, LDAP_BOOL_RESTART);
192                 }
193                 return 0;
194
195         case LDAP_OPT_PROTOCOL_VERSION: {
196                         int vers = * (int *) invalue;
197                         if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) {
198                                 /* not supported */
199                                 break;
200                         }
201                         ld->ld_version = vers;
202                 } return 0;
203
204         case LDAP_OPT_SERVER_CONTROLS:
205         case LDAP_OPT_CLIENT_CONTROLS:
206         case LDAP_OPT_HOST_NAME:
207         case LDAP_OPT_ERROR_NUMBER:
208         case LDAP_OPT_ERROR_STRING:
209                 /* not yet supported */
210                 break;
211         default:
212                 /* bad param */
213                 break;
214         }
215         return -1;
216 }