xref: /titanic_51/usr/src/cmd/idmap/idmapd/adutils.h (revision 2b4a78020b9c38d1b95e2f3fefa6d6e4be382d1f)
1c5c4113dSnw141292 /*
2c5c4113dSnw141292  * CDDL HEADER START
3c5c4113dSnw141292  *
4c5c4113dSnw141292  * The contents of this file are subject to the terms of the
5c5c4113dSnw141292  * Common Development and Distribution License (the "License").
6c5c4113dSnw141292  * You may not use this file except in compliance with the License.
7c5c4113dSnw141292  *
8c5c4113dSnw141292  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9c5c4113dSnw141292  * or http://www.opensolaris.org/os/licensing.
10c5c4113dSnw141292  * See the License for the specific language governing permissions
11c5c4113dSnw141292  * and limitations under the License.
12c5c4113dSnw141292  *
13c5c4113dSnw141292  * When distributing Covered Code, include this CDDL HEADER in each
14c5c4113dSnw141292  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15c5c4113dSnw141292  * If applicable, add the following below this CDDL HEADER, with the
16c5c4113dSnw141292  * fields enclosed by brackets "[]" replaced with your own identifying
17c5c4113dSnw141292  * information: Portions Copyright [yyyy] [name of copyright owner]
18c5c4113dSnw141292  *
19c5c4113dSnw141292  * CDDL HEADER END
20c5c4113dSnw141292  */
21c5c4113dSnw141292 
22c5c4113dSnw141292 /*
230dcc7149Snw141292  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24c5c4113dSnw141292  * Use is subject to license terms.
25c5c4113dSnw141292  */
26c5c4113dSnw141292 
27c5c4113dSnw141292 #ifndef _ADUTILS_H
28c5c4113dSnw141292 #define	_ADUTILS_H
29c5c4113dSnw141292 
30c5c4113dSnw141292 #ifdef __cplusplus
31c5c4113dSnw141292 extern "C" {
32c5c4113dSnw141292 #endif
33c5c4113dSnw141292 
34c5c4113dSnw141292 /*
35c5c4113dSnw141292  * Processes name2sid & sid2name lookups for a given user or computer
36c5c4113dSnw141292  * from an AD Difrectory server using GSSAPI authentication
37c5c4113dSnw141292  */
38c5c4113dSnw141292 
39c5c4113dSnw141292 #include <stdio.h>
40c5c4113dSnw141292 #include <stdlib.h>
41c5c4113dSnw141292 #include <unistd.h>
42c5c4113dSnw141292 #include <lber.h>
43c5c4113dSnw141292 #include <ldap.h>
44c5c4113dSnw141292 #include <sasl/sasl.h>
45c5c4113dSnw141292 #include <string.h>
46c5c4113dSnw141292 #include <ctype.h>
47c5c4113dSnw141292 #include <sys/types.h>
48c5c4113dSnw141292 #include <time.h>
49c5c4113dSnw141292 #include <thread.h>
50c5c4113dSnw141292 #include <synch.h>
51c5c4113dSnw141292 #include "idmap_prot.h"
52*2b4a7802SBaban Kenkre #include "libadutils.h"
53c5c4113dSnw141292 #include <sys/idmap.h>
54c5c4113dSnw141292 
55c5c4113dSnw141292 /*
56c5c4113dSnw141292  * idmapd interfaces stolen? from other idmapd code?
57c5c4113dSnw141292  */
58c5c4113dSnw141292 
59c5c4113dSnw141292 /*
60c5c4113dSnw141292  * Eventually these should be an enum here, but instead we share a
61c5c4113dSnw141292  * namespace with other things in idmapd.
62c5c4113dSnw141292  */
63c5c4113dSnw141292 #define	_IDMAP_T_OTHER		0
64e8c27ec8Sbaban #define	_IDMAP_T_UNDEF		-1
65c5c4113dSnw141292 #define	_IDMAP_T_USER		-1004
66c5c4113dSnw141292 #define	_IDMAP_T_GROUP		-1005
67c5c4113dSnw141292 #define	_IDMAP_T_DOMAIN		-1006
68c5c4113dSnw141292 #define	_IDMAP_T_COMPUTER	-1007
69c5c4113dSnw141292 
70c5c4113dSnw141292 typedef uint32_t rid_t;
71c5c4113dSnw141292 
72c5c4113dSnw141292 typedef struct idmap_query_state idmap_query_state_t;
73c5c4113dSnw141292 
74*2b4a7802SBaban Kenkre int	idmap_add_ds(adutils_ad_t *ad, const char *host, int port);
75c5c4113dSnw141292 
76c5c4113dSnw141292 
77c5c4113dSnw141292 /*
78c5c4113dSnw141292  * Batch lookups
79c5c4113dSnw141292  *
80c5c4113dSnw141292  * Start a batch, add queries to the batch one by one (the output
81c5c4113dSnw141292  * pointers should all differ, so that a query's results don't clobber
82c5c4113dSnw141292  * any other's), end the batch to wait for replies for all outstanding
83c5c4113dSnw141292  * queries.  The output parameters of each query are initialized to NULL
84c5c4113dSnw141292  * or -1 as appropriate.
85c5c4113dSnw141292  *
86c5c4113dSnw141292  * LDAP searches are sent one by one without waiting (i.e., blocking)
87c5c4113dSnw141292  * for replies.  Replies are handled as soon as they are available.
88c5c4113dSnw141292  * Missing replies are waited for only when idmap_lookup_batch_end() is
89c5c4113dSnw141292  * called.
90c5c4113dSnw141292  *
91c5c4113dSnw141292  * If an add1 function returns != 0 then abort the batch by calling
92c5c4113dSnw141292  * idmap_lookup_batch_end(), but note that some queries may have been
93c5c4113dSnw141292  * answered, so check the result code of each query.
94c5c4113dSnw141292  */
95c5c4113dSnw141292 
96c5c4113dSnw141292 /* Start a batch of lookups */
97*2b4a7802SBaban Kenkre idmap_retcode idmap_lookup_batch_start(adutils_ad_t *ad, int nqueries,
98c5c4113dSnw141292 		idmap_query_state_t **state);
99c5c4113dSnw141292 
100c5c4113dSnw141292 /* End a batch and release its idmap_query_state_t object */
1010dcc7149Snw141292 idmap_retcode idmap_lookup_batch_end(idmap_query_state_t **state);
102c5c4113dSnw141292 
103c5c4113dSnw141292 /* Abandon a batch and release its idmap_query_state_t object */
10484decf41Sjp151216 void idmap_lookup_release_batch(idmap_query_state_t **state);
105c5c4113dSnw141292 
106c5c4113dSnw141292 /*
107c5c4113dSnw141292  * Add a name->SID lookup
108c5c4113dSnw141292  *
109c5c4113dSnw141292  *  - 'dname' is optional; if NULL or empty string then 'name' has to be
110c5c4113dSnw141292  *  a user/group name qualified wih a domainname (e.g., foo@domain),
111c5c4113dSnw141292  *  else the 'name' must not be qualified and the domainname must be
112c5c4113dSnw141292  *  passed in 'dname'.
113c5c4113dSnw141292  *
114c5c4113dSnw141292  *  - if 'rid' is NULL then the output SID string will include the last
115c5c4113dSnw141292  *  RID, else it won't and the last RID value will be stored in *rid.
116c5c4113dSnw141292  *
117c5c4113dSnw141292  *  The caller must free() *sid.
118c5c4113dSnw141292  */
119c5c4113dSnw141292 idmap_retcode idmap_name2sid_batch_add1(idmap_query_state_t *state,
120e8c27ec8Sbaban 		const char *name, const char *dname, int eunixtype,
12148258c6bSjp151216 		char **dn, char **attr, char **value, char **canonname,
12248258c6bSjp151216 		char **sid, rid_t *rid, int *sid_type, char **unixname,
12348258c6bSjp151216 		idmap_retcode *rc);
124c5c4113dSnw141292 /*
125c5c4113dSnw141292  * Add a SID->name lookup
126c5c4113dSnw141292  *
127c5c4113dSnw141292  *  - 'rid' is optional; if NULL then 'sid' is expected to have the
128c5c4113dSnw141292  *  user/group RID present, else 'sid' is expected not to have it, and
129c5c4113dSnw141292  *  *rid will be used to qualify the given 'sid'
130c5c4113dSnw141292  *
131c5c4113dSnw141292  *  - 'dname' is optional; if NULL then the fully qualified user/group
132c5c4113dSnw141292  *  name will be stored in *name, else the domain name will be stored in
133c5c4113dSnw141292  *  *dname and the user/group name will be stored in *name without a
134c5c4113dSnw141292  *  domain qualifier.
135c5c4113dSnw141292  *
136c5c4113dSnw141292  *  The caller must free() *name and *dname (if present).
137c5c4113dSnw141292  */
138c5c4113dSnw141292 idmap_retcode idmap_sid2name_batch_add1(idmap_query_state_t *state,
139e8c27ec8Sbaban 		const char *sid, const rid_t *rid, int eunixtype,
14048258c6bSjp151216 		char **dn, char **attr, char **value, char **name,
14148258c6bSjp151216 		char **dname, int *sid_type, char **unixname,
14248258c6bSjp151216 		idmap_retcode *rc);
143e8c27ec8Sbaban 
144e8c27ec8Sbaban /*
145e8c27ec8Sbaban  * Add a unixname->SID lookup
146e8c27ec8Sbaban  */
147e8c27ec8Sbaban idmap_retcode idmap_unixname2sid_batch_add1(idmap_query_state_t *state,
148e8c27ec8Sbaban 		const char *unixname, int is_user, int is_wuser,
14948258c6bSjp151216 		char **dn, char **attr, char **value, char **sid, rid_t *rid,
15048258c6bSjp151216 		char **name, char **dname, int *sid_type, idmap_retcode *rc);
151e8c27ec8Sbaban 
152e8c27ec8Sbaban /*
153e8c27ec8Sbaban  * Set unixname attribute names for the batch for AD-based name mapping
154e8c27ec8Sbaban  */
155e8c27ec8Sbaban void idmap_lookup_batch_set_unixattr(idmap_query_state_t *state,
156e8c27ec8Sbaban 		const char *unixuser_attr, const char *unixgroup_attr);
157c5c4113dSnw141292 
158c5c4113dSnw141292 #ifdef __cplusplus
159c5c4113dSnw141292 }
160c5c4113dSnw141292 #endif
161c5c4113dSnw141292 
162c5c4113dSnw141292 #endif	/* _ADUTILS_H */
163