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