1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _LDAP_COMMON_H
#define _LDAP_COMMON_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __cplusplus
extern "C" {
#endif
#include <ctype.h>
#include <nss_dbdefs.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <signal.h>
#include <lber.h>
#include <ldap.h>
#include <pwd.h>
#include "ns_sldap.h"
#define _ALIASES "aliases"
#define _AUTOMOUNT "automount"
#define _AUTHATTR "auth_attr"
#define _AUUSER "audit_user"
#define _BOOTPARAMS "bootparams"
#define _DEFAULT "default"
#define _ETHERS "ethers"
#define _EXECATTR "exec_attr"
#define _GROUP "group"
#define _PROJECT "project"
#define _HOSTS "hosts"
#define _HOSTS6 "hosts"
#define _NETGROUP "netgroup"
#define _NETMASKS "netmasks"
#define _NETWORKS "networks"
#define _PASSWD "passwd"
#define _PRINTERS "printers"
#define _PROFATTR "prof_attr"
#define _PROTOCOLS "protocols"
#define _PUBLICKEY "publickey"
#define _RPC "rpc"
#define _SERVICES "services"
#define _SHADOW "shadow"
#define _USERATTR "user_attr"
#define _TNRHDB "tnrhdb"
#define _TNRHTP "tnrhtp"
#define NSS_STR_PARSE_NO_ADDR (NSS_STR_PARSE_ERANGE + 100)
#define DOTTEDSUBDOMAIN(string) \
((string != NULL) && (strchr(string, '.') != NULL))
#define SEARCHFILTERLEN 256
#define _NO_VALUE ""
#define TEST_AND_ADJUST(len, buffer, buflen, label) \
/* Use '>=' to ensure there is at least one byte left for '\0' */ \
if (len >= buflen || len < 0) { \
nss_result = NSS_STR_PARSE_ERANGE; \
goto label; \
} \
/* Adjust pointer and available buffer length */ \
buffer += len; \
buflen -= len;
/*
* Superset the nss_backend_t abstract data type. This ADT has
* been extended to include ldap associated data structures.
*/
typedef struct ldap_backend *ldap_backend_ptr;
typedef nss_status_t (*ldap_backend_op_t)(ldap_backend_ptr, void *);
typedef int (*fnf)(ldap_backend_ptr be, nss_XbyY_args_t *argp);
typedef enum {
NSS_LDAP_DB_NONE = 0,
NSS_LDAP_DB_PUBLICKEY = 1,
NSS_LDAP_DB_ETHERS = 2
} nss_ldap_db_type_t;
struct ldap_backend {
ldap_backend_op_t *ops;
nss_dbop_t nops;
char *tablename;
void *enumcookie;
char *filter;
int setcalled;
const char **attrs;
ns_ldap_result_t *result;
fnf ldapobj2str;
void *netgroup_cookie;
void *services_cookie;
char *toglue;
char *buffer;
int buflen;
nss_ldap_db_type_t db_type;
};
extern nss_status_t _nss_ldap_destr(ldap_backend_ptr be, void *a);
extern nss_status_t _nss_ldap_endent(ldap_backend_ptr be, void *a);
extern nss_status_t _nss_ldap_setent(ldap_backend_ptr be, void *a);
extern nss_status_t _nss_ldap_getent(ldap_backend_ptr be, void *a);
nss_backend_t *_nss_ldap_constr(ldap_backend_op_t ops[], int nops,
char *tablename, const char **attrs, fnf ldapobj2str);
extern nss_status_t _nss_ldap_nocb_lookup(ldap_backend_ptr be,
nss_XbyY_args_t *argp, char *database,
char *searchfilter, char *domain,
int (*init_filter_cb)(
const ns_ldap_search_desc_t *desc,
char **realfilter, const void *userdata),
const void *userdata);
extern nss_status_t _nss_ldap_lookup(ldap_backend_ptr be,
nss_XbyY_args_t *argp, char *database,
char *searchfilter, char *domain,
int (*init_filter_cb)(
const ns_ldap_search_desc_t *desc,
char **realfilter, const void *userdata),
const void *userdata);
extern void _clean_ldap_backend(ldap_backend_ptr be);
extern ns_ldap_attr_t *getattr(ns_ldap_result_t *result, int i);
extern const char *_strip_quotes(char *ipaddress);
extern int __nss2herrno(nss_status_t nsstat);
extern int propersubdomain(char *domain, char *subdomain);
extern int chophostdomain(char *string, char *host, char *domain);
extern char *_get_domain_name(char *cdn);
extern int _merge_SSD_filter(const ns_ldap_search_desc_t *desc,
char **realfilter, const void *userdata);
extern int _ldap_filter_name(char *filter_name, const char *name,
int filter_name_size);
extern void _nss_services_cookie_free(void **cookieP);
#ifdef DEBUG
extern int printresult(ns_ldap_result_t *result);
#endif /* DEBUG */
#ifdef __cplusplus
}
#endif
#endif /* _LDAP_COMMON_H */
|