Unleashed v1.4
[unleashed.git] / usr / src / lib / nsswitch / ldap / common / ldap_common.h
blobbf31c7fd4f5ba04934b366f3f4995fbece51344a
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
25 #ifndef _LDAP_COMMON_H
26 #define _LDAP_COMMON_H
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
32 #include <ctype.h>
33 #include <nss_dbdefs.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <strings.h>
37 #include <signal.h>
38 #include <lber.h>
39 #include <ldap.h>
40 #include <pwd.h>
41 #include "ns_sldap.h"
43 #define _ALIASES "aliases"
44 #define _AUTOMOUNT "automount"
45 #define _AUTHATTR "auth_attr"
46 #define _BOOTPARAMS "bootparams"
47 #define _DEFAULT "default"
48 #define _ETHERS "ethers"
49 #define _EXECATTR "exec_attr"
50 #define _GROUP "group"
51 #define _PROJECT "project"
52 #define _HOSTS "hosts"
53 #define _HOSTS6 "hosts"
54 #define _NETGROUP "netgroup"
55 #define _NETMASKS "netmasks"
56 #define _NETWORKS "networks"
57 #define _PASSWD "passwd"
58 #define _PRINTERS "printers"
59 #define _PROFATTR "prof_attr"
60 #define _PROTOCOLS "protocols"
61 #define _PUBLICKEY "publickey"
62 #define _RPC "rpc"
63 #define _SERVICES "services"
64 #define _SHADOW "shadow"
65 #define _USERATTR "user_attr"
67 #define NSS_STR_PARSE_NO_ADDR (NSS_STR_PARSE_ERANGE + 100)
68 #define NSS_STR_PARSE_NO_RESULT (NSS_STR_PARSE_ERANGE + 101)
70 #define DOTTEDSUBDOMAIN(string) \
71 ((string != NULL) && (strchr(string, '.') != NULL))
72 #define SEARCHFILTERLEN 256
74 #define _NO_VALUE ""
76 #define TEST_AND_ADJUST(len, buffer, buflen, label) \
77 /* Use '>=' to ensure there is at least one byte left for '\0' */ \
78 if (len >= buflen || len < 0) { \
79 nss_result = NSS_STR_PARSE_ERANGE; \
80 goto label; \
81 } \
82 /* Adjust pointer and available buffer length */ \
83 buffer += len; \
84 buflen -= len;
87 * We need to use UID_NOBODY and GID_NOBODY as strings. Therefore we use
88 * snprintf to convert [U|G]ID_NOBODY into a string. The target buffer
89 * size was chosen as 21 to allow the largest 64-bit number to be stored
90 * as string in it. Right now uid_t and gid_t are 32-bit so we don't
91 * really need 21 characters but it does allow for future expansion
92 * without having to modify this code.
94 #define NOBODY_STR_LEN 21
98 * Superset the nss_backend_t abstract data type. This ADT has
99 * been extended to include ldap associated data structures.
102 typedef struct ldap_backend *ldap_backend_ptr;
103 typedef nss_status_t (*ldap_backend_op_t)(ldap_backend_ptr, void *);
104 typedef int (*fnf)(ldap_backend_ptr be, nss_XbyY_args_t *argp);
106 typedef enum {
107 NSS_LDAP_DB_NONE = 0,
108 NSS_LDAP_DB_PUBLICKEY = 1,
109 NSS_LDAP_DB_ETHERS = 2
110 } nss_ldap_db_type_t;
112 struct ldap_backend {
113 ldap_backend_op_t *ops;
114 nss_dbop_t nops;
115 char *tablename;
116 void *enumcookie;
117 char *filter;
118 char *sortattr;
119 int setcalled;
120 const char **attrs;
121 ns_ldap_result_t *result;
122 fnf ldapobj2str;
123 void *netgroup_cookie;
124 void *services_cookie;
125 char *toglue;
126 char *buffer;
127 int buflen;
128 nss_ldap_db_type_t db_type;
131 extern nss_status_t _nss_ldap_destr(ldap_backend_ptr be, void *a);
132 extern nss_status_t _nss_ldap_endent(ldap_backend_ptr be, void *a);
133 extern nss_status_t _nss_ldap_setent(ldap_backend_ptr be, void *a);
134 extern nss_status_t _nss_ldap_getent(ldap_backend_ptr be, void *a);
135 nss_backend_t *_nss_ldap_constr(ldap_backend_op_t ops[], int nops,
136 char *tablename, const char **attrs, fnf ldapobj2str);
137 extern nss_status_t _nss_ldap_nocb_lookup(ldap_backend_ptr be,
138 nss_XbyY_args_t *argp, char *database,
139 char *searchfilter, char *domain,
140 int (*init_filter_cb)(
141 const ns_ldap_search_desc_t *desc,
142 char **realfilter, const void *userdata),
143 const void *userdata);
144 extern nss_status_t _nss_ldap_lookup(ldap_backend_ptr be,
145 nss_XbyY_args_t *argp, char *database,
146 char *searchfilter, char *domain,
147 int (*init_filter_cb)(
148 const ns_ldap_search_desc_t *desc,
149 char **realfilter, const void *userdata),
150 const void *userdata);
151 extern void _clean_ldap_backend(ldap_backend_ptr be);
153 extern ns_ldap_attr_t *getattr(ns_ldap_result_t *result, int i);
154 extern const char *_strip_quotes(char *ipaddress);
155 extern int __nss2herrno(nss_status_t nsstat);
156 extern int propersubdomain(char *domain, char *subdomain);
157 extern int chophostdomain(char *string, char *host, char *domain);
158 extern char *_get_domain_name(char *cdn);
159 extern int _merge_SSD_filter(const ns_ldap_search_desc_t *desc,
160 char **realfilter, const void *userdata);
161 extern int _ldap_filter_name(char *filter_name, const char *name,
162 int filter_name_size);
164 extern void _nss_services_cookie_free(void **cookieP);
165 extern nss_status_t switch_err(int rc, ns_ldap_error_t *error);
167 #ifdef DEBUG
168 extern int printresult(ns_ldap_result_t *result);
169 #endif /* DEBUG */
171 #ifdef __cplusplus
173 #endif
175 #endif /* _LDAP_COMMON_H */