xref: /illumos-gate/usr/src/lib/libidmap/common/idmap.h (revision 24f5a37652e188ebdcdd6da454511686935025df)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
24  */
25 
26 /*
27  * Header File for Clients of Native Identity Mapping Service
28  */
29 
30 #ifndef _IDMAP_H
31 #define	_IDMAP_H
32 
33 
34 #include <stdlib.h>
35 #include <ctype.h>
36 #include <sys/param.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <sys/idmap.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * The ifdef's for these two accomodate duplicate definitions in
47  * lib/smbsrv/libfksmbsrv/common/sys/kidmap.h  See notes there.
48  */
49 
50 /* Status */
51 #ifndef	_IDMAP_STAT_TYPE
52 #define	_IDMAP_STAT_TYPE
53 typedef int32_t	idmap_stat;
54 #endif	/* _IDMAP_STAT_TYPE */
55 
56 /* Opaque get handle */
57 #ifndef	_IDMAP_GET_HANDLE_T
58 #define	_IDMAP_GET_HANDLE_T
59 typedef struct idmap_get_handle idmap_get_handle_t;
60 #endif	/* _IDMAP_GET_HANDLE_T */
61 
62 typedef uint32_t	idmap_rid_t;
63 
64 /* Logger prototype which is based on syslog */
65 typedef void (*idmap_logger_t)(int, const char *, ...);
66 
67 /*
68  * Setup API
69  */
70 
71 /* Status code to string */
72 extern const char *idmap_stat2string(idmap_stat);
73 
74 /* Free memory allocated by the API */
75 extern void idmap_free(void *);
76 
77 
78 /*
79  * Supported flag values for mapping requests.
80  * These flag values are applicable to the batch API and the
81  * Windows Name API below.
82  */
83 /* Use the libidmap cache */
84 #define	IDMAP_REQ_FLG_USE_CACHE	0x00000010
85 
86 /*
87  * API to batch SID to UID/GID mapping requests
88  */
89 /* Create handle */
90 extern idmap_stat idmap_get_create(idmap_get_handle_t **);
91 
92 /* Given SID, get UID */
93 extern idmap_stat idmap_get_uidbysid(idmap_get_handle_t *, char *,
94 	idmap_rid_t, int, uid_t *, idmap_stat *);
95 
96 /* Given SID, get GID */
97 extern idmap_stat idmap_get_gidbysid(idmap_get_handle_t *, char *,
98 	idmap_rid_t, int, gid_t *, idmap_stat *);
99 
100 /* Given SID, get UID or GID */
101 extern idmap_stat idmap_get_pidbysid(idmap_get_handle_t *, char *,
102 	idmap_rid_t, int, uid_t *, int *, idmap_stat *);
103 
104 /* Given UID, get SID */
105 extern idmap_stat idmap_get_sidbyuid(idmap_get_handle_t *, uid_t, int,
106 	char **, idmap_rid_t *, idmap_stat *);
107 
108 /* Given GID, get SID */
109 extern idmap_stat idmap_get_sidbygid(idmap_get_handle_t *, gid_t, int,
110 	char **, idmap_rid_t *, idmap_stat *);
111 
112 /* Process the batched requests */
113 extern idmap_stat idmap_get_mappings(idmap_get_handle_t *);
114 
115 /* Destroy the handle */
116 extern void idmap_get_destroy(idmap_get_handle_t *);
117 
118 
119 /*
120  * API to get Windows name by UID/GID and vice-versa
121  */
122 /* Given UID, get Windows name */
123 extern idmap_stat idmap_getwinnamebyuid(uid_t, int, char **, char **);
124 
125 /* Given GID, get Windows name */
126 extern idmap_stat idmap_getwinnamebygid(gid_t, int, char **, char **);
127 
128 /* Given PID, get Windows name */
129 extern idmap_stat idmap_getwinnamebypid(uid_t, int, int, char **, char **);
130 
131 /* Given Windows name, get UID */
132 extern idmap_stat idmap_getuidbywinname(const char *, const char *,
133 	int, uid_t *);
134 
135 /* Given Windows name, get GID */
136 extern idmap_stat idmap_getgidbywinname(const char *, const char *,
137 	int, gid_t *);
138 
139 
140 /* Logger */
141 extern void idmap_set_logger(idmap_logger_t funct);
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif /* _IDMAP_H */
148