sss_idmap  2.5.2
sss_idmap.h
1 /*
2  SSSD
3 
4  ID-mapping library
5 
6  Authors:
7  Sumit Bose <sbose@redhat.com>
8 
9  Copyright (C) 2012 Red Hat
10 
11  This program is free software; you can redistribute it and/or modify
12  it under the terms of the GNU General Public License as published by
13  the Free Software Foundation; either version 3 of the License, or
14  (at your option) any later version.
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
25 #ifndef SSS_IDMAP_H_
26 #define SSS_IDMAP_H_
27 
28 #include <stdlib.h>
29 #include <stdint.h>
30 #include <stdbool.h>
31 #include <sys/types.h>
32 
33 #define DOM_SID_PREFIX "S-1-5-21-"
34 #define DOM_SID_PREFIX_LEN (sizeof(DOM_SID_PREFIX) - 1)
35 
49 
52 
55 
58 
61 
64 
67 
70 
73 
76 
79 
82 
85 
88 
92 };
93 
97 typedef void *(idmap_alloc_func)(size_t size, void *pvt);
98 typedef void (idmap_free_func)(void *ptr, void *pvt);
99 
103 typedef enum idmap_error_code (*idmap_store_cb)(const char *dom_name,
104  const char *dom_sid,
105  const char *range_id,
106  uint32_t min_id,
107  uint32_t max_id,
108  uint32_t first_rid,
109  void *pvt);
110 
117  uint32_t min;
118  uint32_t max;
119 };
120 
124 struct sss_dom_sid;
125 
129 struct sss_idmap_ctx;
130 
136 struct dom_sid;
137 
152  void *alloc_pvt,
153  idmap_free_func *free_func,
154  struct sss_idmap_ctx **ctx);
155 
162 enum idmap_error_code
163 sss_idmap_ctx_set_autorid(struct sss_idmap_ctx *ctx, bool use_autorid);
164 
171 enum idmap_error_code
172 sss_idmap_ctx_set_lower(struct sss_idmap_ctx *ctx, id_t lower);
173 
180 enum idmap_error_code
181 sss_idmap_ctx_set_upper(struct sss_idmap_ctx *ctx, id_t upper);
182 
189 enum idmap_error_code
190 sss_idmap_ctx_set_rangesize(struct sss_idmap_ctx *ctx, id_t rangesize);
191 
199 enum idmap_error_code
200 sss_idmap_ctx_set_extra_slice_init(struct sss_idmap_ctx *ctx,
201  int extra_slice_init);
202 
209 enum idmap_error_code
210 sss_idmap_ctx_get_autorid(struct sss_idmap_ctx *ctx, bool *_autorid);
211 
218 enum idmap_error_code
219 sss_idmap_ctx_get_lower(struct sss_idmap_ctx *ctx, id_t *_lower);
220 
227 enum idmap_error_code
228 sss_idmap_ctx_get_upper(struct sss_idmap_ctx *ctx, id_t *_upper);
229 
236 enum idmap_error_code
237 sss_idmap_ctx_get_rangesize(struct sss_idmap_ctx *ctx, id_t *rangesize);
238 
256 enum idmap_error_code sss_idmap_calculate_range(struct sss_idmap_ctx *ctx,
257  const char *dom_sid,
258  id_t *slice_num,
259  struct sss_idmap_range *range);
260 
278 enum idmap_error_code sss_idmap_add_domain(struct sss_idmap_ctx *ctx,
279  const char *domain_name,
280  const char *domain_sid,
281  struct sss_idmap_range *range);
282 
311 enum idmap_error_code sss_idmap_add_domain_ex(struct sss_idmap_ctx *ctx,
312  const char *domain_name,
313  const char *domain_sid,
314  struct sss_idmap_range *range,
315  const char *range_id,
316  uint32_t rid,
317  bool external_mapping);
318 
351 enum idmap_error_code
352 sss_idmap_add_auto_domain_ex(struct sss_idmap_ctx *ctx,
353  const char *domain_name,
354  const char *domain_sid,
355  struct sss_idmap_range *range,
356  const char *range_id,
357  uint32_t rid,
358  bool external_mapping,
359  idmap_store_cb cb,
360  void *pvt);
361 
380 enum idmap_error_code sss_idmap_check_collision(struct sss_idmap_ctx *ctx,
381  char *n_name, char *n_sid,
382  struct sss_idmap_range *n_range,
383  uint32_t n_first_rid,
384  char *n_range_id,
385  bool n_external_mapping);
386 
414 enum idmap_error_code sss_idmap_check_collision_ex(const char *o_name,
415  const char *o_sid,
416  struct sss_idmap_range *o_range,
417  uint32_t o_first_rid,
418  const char *o_range_id,
419  bool o_external_mapping,
420  const char *n_name,
421  const char *n_sid,
422  struct sss_idmap_range *n_range,
423  uint32_t n_first_rid,
424  const char *n_range_id,
425  bool n_external_mapping);
440 enum idmap_error_code sss_idmap_sid_to_unix(struct sss_idmap_ctx *ctx,
441  const char *sid,
442  uint32_t *id);
443 
458 enum idmap_error_code sss_idmap_dom_sid_to_unix(struct sss_idmap_ctx *ctx,
459  struct sss_dom_sid *dom_sid,
460  uint32_t *id);
461 
477 enum idmap_error_code sss_idmap_bin_sid_to_unix(struct sss_idmap_ctx *ctx,
478  uint8_t *bin_sid,
479  size_t length,
480  uint32_t *id);
481 
496 enum idmap_error_code sss_idmap_smb_sid_to_unix(struct sss_idmap_ctx *ctx,
497  struct dom_sid *smb_sid,
498  uint32_t *id);
499 
514 enum idmap_error_code sss_idmap_check_sid_unix(struct sss_idmap_ctx *ctx,
515  const char *sid,
516  uint32_t id);
517 
532 enum idmap_error_code sss_idmap_check_dom_sid_unix(struct sss_idmap_ctx *ctx,
533  struct sss_dom_sid *dom_sid,
534  uint32_t id);
535 
551 enum idmap_error_code sss_idmap_check_bin_sid_unix(struct sss_idmap_ctx *ctx,
552  uint8_t *bin_sid,
553  size_t length,
554  uint32_t id);
555 
571 enum idmap_error_code sss_idmap_check_smb_sid_unix(struct sss_idmap_ctx *ctx,
572  struct dom_sid *smb_sid,
573  uint32_t id);
574 
589 enum idmap_error_code sss_idmap_unix_to_sid(struct sss_idmap_ctx *ctx,
590  uint32_t id,
591  char **sid);
592 
606 enum idmap_error_code sss_idmap_unix_to_dom_sid(struct sss_idmap_ctx *ctx,
607  uint32_t id,
608  struct sss_dom_sid **dom_sid);
609 
625 enum idmap_error_code sss_idmap_unix_to_bin_sid(struct sss_idmap_ctx *ctx,
626  uint32_t id,
627  uint8_t **bin_sid,
628  size_t *length);
629 
638 enum idmap_error_code sss_idmap_free(struct sss_idmap_ctx *ctx);
639 
649 enum idmap_error_code sss_idmap_free_sid(struct sss_idmap_ctx *ctx,
650  char *sid);
651 
661 enum idmap_error_code sss_idmap_free_dom_sid(struct sss_idmap_ctx *ctx,
662  struct sss_dom_sid *dom_sid);
663 
673 enum idmap_error_code sss_idmap_free_smb_sid(struct sss_idmap_ctx *ctx,
674  struct dom_sid *smb_sid);
675 
685 enum idmap_error_code sss_idmap_free_bin_sid(struct sss_idmap_ctx *ctx,
686  uint8_t *bin_sid);
687 
696 const char *idmap_error_string(enum idmap_error_code err);
697 
707 bool is_domain_sid(const char *str);
708 
728 enum idmap_error_code
729 sss_idmap_domain_has_algorithmic_mapping(struct sss_idmap_ctx *ctx,
730  const char *dom_sid,
731  bool *has_algorithmic_mapping);
732 
751 enum idmap_error_code
752 sss_idmap_domain_by_name_has_algorithmic_mapping(struct sss_idmap_ctx *ctx,
753  const char *dom_name,
754  bool *has_algorithmic_mapping);
755 
769 enum idmap_error_code sss_idmap_bin_sid_to_dom_sid(struct sss_idmap_ctx *ctx,
770  const uint8_t *bin_sid,
771  size_t length,
772  struct sss_dom_sid **dom_sid);
773 
787 enum idmap_error_code sss_idmap_bin_sid_to_sid(struct sss_idmap_ctx *ctx,
788  const uint8_t *bin_sid,
789  size_t length,
790  char **sid);
791 
805 enum idmap_error_code sss_idmap_dom_sid_to_bin_sid(struct sss_idmap_ctx *ctx,
806  struct sss_dom_sid *dom_sid,
807  uint8_t **bin_sid,
808  size_t *length);
809 
823 enum idmap_error_code sss_idmap_sid_to_bin_sid(struct sss_idmap_ctx *ctx,
824  const char *sid,
825  uint8_t **bin_sid,
826  size_t *length);
827 
840 enum idmap_error_code sss_idmap_dom_sid_to_sid(struct sss_idmap_ctx *ctx,
841  struct sss_dom_sid *dom_sid,
842  char **sid);
843 
856 enum idmap_error_code sss_idmap_sid_to_dom_sid(struct sss_idmap_ctx *ctx,
857  const char *sid,
858  struct sss_dom_sid **dom_sid);
859 
872 enum idmap_error_code sss_idmap_sid_to_smb_sid(struct sss_idmap_ctx *ctx,
873  const char *sid,
874  struct dom_sid **smb_sid);
875 
888 enum idmap_error_code sss_idmap_smb_sid_to_sid(struct sss_idmap_ctx *ctx,
889  struct dom_sid *smb_sid,
890  char **sid);
891 
904 enum idmap_error_code sss_idmap_dom_sid_to_smb_sid(struct sss_idmap_ctx *ctx,
905  struct sss_dom_sid *dom_sid,
906  struct dom_sid **smb_sid);
907 
920 enum idmap_error_code sss_idmap_smb_sid_to_dom_sid(struct sss_idmap_ctx *ctx,
921  struct dom_sid *smb_sid,
922  struct sss_dom_sid **dom_sid);
923 
937 enum idmap_error_code sss_idmap_bin_sid_to_smb_sid(struct sss_idmap_ctx *ctx,
938  const uint8_t *bin_sid,
939  size_t length,
940  struct dom_sid **smb_sid);
941 
955 enum idmap_error_code sss_idmap_smb_sid_to_bin_sid(struct sss_idmap_ctx *ctx,
956  struct dom_sid *smb_sid,
957  uint8_t **bin_sid,
958  size_t *length);
962 #endif /* SSS_IDMAP_H_ */
enum idmap_error_code sss_idmap_sid_to_bin_sid(struct sss_idmap_ctx *ctx, const char *sid, uint8_t **bin_sid, size_t *length)
Convert SID string to binary SID.
The provided SID was not found.
Definition: sss_idmap.h:69
enum idmap_error_code sss_idmap_ctx_get_upper(struct sss_idmap_ctx *ctx, id_t *_upper)
Get the upper bound of the range of POSIX IDs.
enum idmap_error_code sss_idmap_check_dom_sid_unix(struct sss_idmap_ctx *ctx, struct sss_dom_sid *dom_sid, uint32_t id)
Check if a SID structure and a unix UID or GID belong to the same range.
Success.
Definition: sss_idmap.h:48
Function is not yet implemented.
Definition: sss_idmap.h:51
enum idmap_error_code sss_idmap_calculate_range(struct sss_idmap_ctx *ctx, const char *dom_sid, id_t *slice_num, struct sss_idmap_range *range)
Calculate new range of available POSIX IDs.
enum idmap_error_code sss_idmap_bin_sid_to_unix(struct sss_idmap_ctx *ctx, uint8_t *bin_sid, size_t length, uint32_t *id)
Translate a binary SID to a unix UID or GID.
The provided SID is a built-in one.
Definition: sss_idmap.h:75
enum idmap_error_code sss_idmap_ctx_get_rangesize(struct sss_idmap_ctx *ctx, id_t *rangesize)
Get the range size of POSIX IDs available for single domain.
enum idmap_error_code sss_idmap_ctx_set_extra_slice_init(struct sss_idmap_ctx *ctx, int extra_slice_init)
Set the number of secondary slices available for domain.
enum idmap_error_code sss_idmap_check_bin_sid_unix(struct sss_idmap_ctx *ctx, uint8_t *bin_sid, size_t length, uint32_t id)
Check if a binary SID and a unix UID or GID belong to the same range.
The provided idmap context is invalid.
Definition: sss_idmap.h:63
enum idmap_error_code sss_idmap_sid_to_unix(struct sss_idmap_ctx *ctx, const char *sid, uint32_t *id)
Translate SID to a unix UID or GID.
The provided UID or GID could not be mapped.
Definition: sss_idmap.h:72
enum idmap_error_code sss_idmap_ctx_set_upper(struct sss_idmap_ctx *ctx, id_t upper)
Set the upper bound of the range of POSIX IDs.
enum idmap_error_code sss_idmap_init(idmap_alloc_func *alloc_func, void *alloc_pvt, idmap_free_func *free_func, struct sss_idmap_ctx **ctx)
Initialize idmap context.
bool is_domain_sid(const char *str)
Check if given string can be used as domain SID.
enum idmap_error_code sss_idmap_free_dom_sid(struct sss_idmap_ctx *ctx, struct sss_dom_sid *dom_sid)
Free mapped domain SID.
enum idmap_error_code sss_idmap_unix_to_dom_sid(struct sss_idmap_ctx *ctx, uint32_t id, struct sss_dom_sid **dom_sid)
Translate unix UID or GID to a SID structure.
enum idmap_error_code sss_idmap_dom_sid_to_bin_sid(struct sss_idmap_ctx *ctx, struct sss_dom_sid *dom_sid, uint8_t **bin_sid, size_t *length)
Convert SID structure to binary SID.
External source should be consulted for idmapping.
Definition: sss_idmap.h:84
enum idmap_error_code sss_idmap_add_domain_ex(struct sss_idmap_ctx *ctx, const char *domain_name, const char *domain_sid, struct sss_idmap_range *range, const char *range_id, uint32_t rid, bool external_mapping)
Add a domain with the first mappable RID to the idmap context.
General error.
Definition: sss_idmap.h:54
enum idmap_error_code sss_idmap_ctx_set_rangesize(struct sss_idmap_ctx *ctx, id_t rangesize)
Set the range size of POSIX IDs available for single domain.
const char * idmap_error_string(enum idmap_error_code err)
Translate error code to a string.
enum idmap_error_code(* idmap_store_cb)(const char *dom_name, const char *dom_sid, const char *range_id, uint32_t min_id, uint32_t max_id, uint32_t first_rid, void *pvt)
Typedef for storing mappings of dynamically created domains.
Definition: sss_idmap.h:103
enum idmap_error_code sss_idmap_add_auto_domain_ex(struct sss_idmap_ctx *ctx, const char *domain_name, const char *domain_sid, struct sss_idmap_range *range, const char *range_id, uint32_t rid, bool external_mapping, idmap_store_cb cb, void *pvt)
Add a domain with the first mappable RID to the idmap context and generate automatically secondary sl...
enum idmap_error_code sss_idmap_smb_sid_to_dom_sid(struct sss_idmap_ctx *ctx, struct dom_sid *smb_sid, struct sss_dom_sid **dom_sid)
Convert Samba dom_sid structure to SID structure.
enum idmap_error_code sss_idmap_sid_to_dom_sid(struct sss_idmap_ctx *ctx, const char *sid, struct sss_dom_sid **dom_sid)
Convert SID string to SID structure.
Ran out of memory during processing.
Definition: sss_idmap.h:57
Sentinel to indicate the end of the error code list, not returned by any call.
Definition: sss_idmap.h:91
enum idmap_error_code sss_idmap_domain_has_algorithmic_mapping(struct sss_idmap_ctx *ctx, const char *dom_sid, bool *has_algorithmic_mapping)
Check if a domain is configured with algorithmic mapping.
enum idmap_error_code sss_idmap_check_collision(struct sss_idmap_ctx *ctx, char *n_name, char *n_sid, struct sss_idmap_range *n_range, uint32_t n_first_rid, char *n_range_id, bool n_external_mapping)
Check if a new range would collide with any existing one.
enum idmap_error_code sss_idmap_smb_sid_to_bin_sid(struct sss_idmap_ctx *ctx, struct dom_sid *smb_sid, uint8_t **bin_sid, size_t *length)
Convert Samba dom_sid structure to binary SID.
enum idmap_error_code sss_idmap_free_sid(struct sss_idmap_ctx *ctx, char *sid)
Free mapped SID.
enum idmap_error_code sss_idmap_ctx_set_autorid(struct sss_idmap_ctx *ctx, bool use_autorid)
Set/unset autorid compatibility mode.
enum idmap_error_code sss_idmap_check_sid_unix(struct sss_idmap_ctx *ctx, const char *sid, uint32_t id)
Check if a SID and a unix UID or GID belong to the same range.
enum idmap_error_code sss_idmap_free_smb_sid(struct sss_idmap_ctx *ctx, struct dom_sid *smb_sid)
Free mapped Samba SID.
enum idmap_error_code sss_idmap_free_bin_sid(struct sss_idmap_ctx *ctx, uint8_t *bin_sid)
Free mapped binary SID.
New domain collides with existing one.
Definition: sss_idmap.h:81
No domain added.
Definition: sss_idmap.h:60
enum idmap_error_code sss_idmap_ctx_set_lower(struct sss_idmap_ctx *ctx, id_t lower)
Set the lower bound of the range of POSIX IDs.
The provided SID is invalid.
Definition: sss_idmap.h:66
enum idmap_error_code sss_idmap_add_domain(struct sss_idmap_ctx *ctx, const char *domain_name, const char *domain_sid, struct sss_idmap_range *range)
Add a domain to the idmap context.
enum idmap_error_code sss_idmap_free(struct sss_idmap_ctx *ctx)
Free all the allocated memory of the idmap context.
enum idmap_error_code sss_idmap_unix_to_bin_sid(struct sss_idmap_ctx *ctx, uint32_t id, uint8_t **bin_sid, size_t *length)
Translate unix UID or GID to a binary SID.
enum idmap_error_code sss_idmap_check_smb_sid_unix(struct sss_idmap_ctx *ctx, struct dom_sid *smb_sid, uint32_t id)
Check if a Samba dom_sid structure and a unix UID or GID belong to the same range.
No more free slices.
Definition: sss_idmap.h:78
enum idmap_error_code sss_idmap_sid_to_smb_sid(struct sss_idmap_ctx *ctx, const char *sid, struct dom_sid **smb_sid)
Convert SID string to Samba dom_sid structure.
void *() idmap_alloc_func(size_t size, void *pvt)
Typedef for memory allocation functions.
Definition: sss_idmap.h:97
Structure for id ranges FIXME: this struct might change when it is clear how ranges are handled on th...
Definition: sss_idmap.h:116
enum idmap_error_code sss_idmap_smb_sid_to_sid(struct sss_idmap_ctx *ctx, struct dom_sid *smb_sid, char **sid)
Convert Samba dom_sid structure to SID string.
enum idmap_error_code sss_idmap_unix_to_sid(struct sss_idmap_ctx *ctx, uint32_t id, char **sid)
Translate unix UID or GID to a SID.
enum idmap_error_code sss_idmap_ctx_get_lower(struct sss_idmap_ctx *ctx, id_t *_lower)
Get the lower bound of the range of POSIX IDs.
enum idmap_error_code sss_idmap_dom_sid_to_smb_sid(struct sss_idmap_ctx *ctx, struct sss_dom_sid *dom_sid, struct dom_sid **smb_sid)
Convert SID stucture to Samba dom_sid structure.
enum idmap_error_code sss_idmap_bin_sid_to_smb_sid(struct sss_idmap_ctx *ctx, const uint8_t *bin_sid, size_t length, struct dom_sid **smb_sid)
Convert binary SID to Samba dom_sid structure.
enum idmap_error_code sss_idmap_smb_sid_to_unix(struct sss_idmap_ctx *ctx, struct dom_sid *smb_sid, uint32_t *id)
Translate a Samba dom_sid stucture to a unix UID or GID.
enum idmap_error_code sss_idmap_dom_sid_to_unix(struct sss_idmap_ctx *ctx, struct sss_dom_sid *dom_sid, uint32_t *id)
Translate a SID stucture to a unix UID or GID.
enum idmap_error_code sss_idmap_bin_sid_to_dom_sid(struct sss_idmap_ctx *ctx, const uint8_t *bin_sid, size_t length, struct sss_dom_sid **dom_sid)
Convert binary SID to SID structure.
enum idmap_error_code sss_idmap_bin_sid_to_sid(struct sss_idmap_ctx *ctx, const uint8_t *bin_sid, size_t length, char **sid)
Convert binary SID to SID string.
idmap_error_code
Error codes used by libsss_idmap.
Definition: sss_idmap.h:46
enum idmap_error_code sss_idmap_ctx_get_autorid(struct sss_idmap_ctx *ctx, bool *_autorid)
Check if autorid compatibility mode is set.
enum idmap_error_code sss_idmap_check_collision_ex(const char *o_name, const char *o_sid, struct sss_idmap_range *o_range, uint32_t o_first_rid, const char *o_range_id, bool o_external_mapping, const char *n_name, const char *n_sid, struct sss_idmap_range *n_range, uint32_t n_first_rid, const char *n_range_id, bool n_external_mapping)
Check if two ranges would collide.
enum idmap_error_code sss_idmap_dom_sid_to_sid(struct sss_idmap_ctx *ctx, struct sss_dom_sid *dom_sid, char **sid)
Convert SID structure to SID string.
The provided name was not found.
Definition: sss_idmap.h:87
enum idmap_error_code sss_idmap_domain_by_name_has_algorithmic_mapping(struct sss_idmap_ctx *ctx, const char *dom_name, bool *has_algorithmic_mapping)
Check if a domain is configured with algorithmic mapping.