sss_idmap  1.13.0
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 };
89 
93 typedef void *(idmap_alloc_func)(size_t size, void *pvt);
94 typedef void (idmap_free_func)(void *ptr, void *pvt);
95 
102  uint32_t min;
103  uint32_t max;
104 };
105 
109 struct sss_dom_sid;
110 
114 struct sss_idmap_ctx;
115 
121 struct dom_sid;
122 
137  void *alloc_pvt,
138  idmap_free_func *free_func,
139  struct sss_idmap_ctx **ctx);
140 
147 enum idmap_error_code
148 sss_idmap_ctx_set_autorid(struct sss_idmap_ctx *ctx, bool use_autorid);
149 
156 enum idmap_error_code
157 sss_idmap_ctx_set_lower(struct sss_idmap_ctx *ctx, id_t lower);
158 
165 enum idmap_error_code
166 sss_idmap_ctx_set_upper(struct sss_idmap_ctx *ctx, id_t upper);
167 
174 enum idmap_error_code
175 sss_idmap_ctx_set_rangesize(struct sss_idmap_ctx *ctx, id_t rangesize);
176 
183 enum idmap_error_code
184 sss_idmap_ctx_get_autorid(struct sss_idmap_ctx *ctx, bool *_autorid);
185 
192 enum idmap_error_code
193 sss_idmap_ctx_get_lower(struct sss_idmap_ctx *ctx, id_t *_lower);
194 
201 enum idmap_error_code
202 sss_idmap_ctx_get_upper(struct sss_idmap_ctx *ctx, id_t *_upper);
203 
210 enum idmap_error_code
211 sss_idmap_ctx_get_rangesize(struct sss_idmap_ctx *ctx, id_t *rangesize);
212 
230 enum idmap_error_code sss_idmap_calculate_range(struct sss_idmap_ctx *ctx,
231  const char *dom_sid,
232  id_t *slice_num,
233  struct sss_idmap_range *range);
234 
252 enum idmap_error_code sss_idmap_add_domain(struct sss_idmap_ctx *ctx,
253  const char *domain_name,
254  const char *domain_sid,
255  struct sss_idmap_range *range);
256 
285 enum idmap_error_code sss_idmap_add_domain_ex(struct sss_idmap_ctx *ctx,
286  const char *domain_name,
287  const char *domain_sid,
288  struct sss_idmap_range *range,
289  const char *range_id,
290  uint32_t rid,
291  bool external_mapping);
292 
311 enum idmap_error_code sss_idmap_check_collision(struct sss_idmap_ctx *ctx,
312  char *n_name, char *n_sid,
313  struct sss_idmap_range *n_range,
314  uint32_t n_first_rid,
315  char *n_range_id,
316  bool n_external_mapping);
317 
345 enum idmap_error_code sss_idmap_check_collision_ex(const char *o_name,
346  const char *o_sid,
347  struct sss_idmap_range *o_range,
348  uint32_t o_first_rid,
349  const char *o_range_id,
350  bool o_external_mapping,
351  const char *n_name,
352  const char *n_sid,
353  struct sss_idmap_range *n_range,
354  uint32_t n_first_rid,
355  const char *n_range_id,
356  bool n_external_mapping);
371 enum idmap_error_code sss_idmap_sid_to_unix(struct sss_idmap_ctx *ctx,
372  const char *sid,
373  uint32_t *id);
374 
389 enum idmap_error_code sss_idmap_dom_sid_to_unix(struct sss_idmap_ctx *ctx,
390  struct sss_dom_sid *dom_sid,
391  uint32_t *id);
392 
408 enum idmap_error_code sss_idmap_bin_sid_to_unix(struct sss_idmap_ctx *ctx,
409  uint8_t *bin_sid,
410  size_t length,
411  uint32_t *id);
412 
427 enum idmap_error_code sss_idmap_smb_sid_to_unix(struct sss_idmap_ctx *ctx,
428  struct dom_sid *smb_sid,
429  uint32_t *id);
430 
445 enum idmap_error_code sss_idmap_check_sid_unix(struct sss_idmap_ctx *ctx,
446  const char *sid,
447  uint32_t id);
448 
463 enum idmap_error_code sss_idmap_check_dom_sid_unix(struct sss_idmap_ctx *ctx,
464  struct sss_dom_sid *dom_sid,
465  uint32_t id);
466 
482 enum idmap_error_code sss_idmap_check_bin_sid_unix(struct sss_idmap_ctx *ctx,
483  uint8_t *bin_sid,
484  size_t length,
485  uint32_t id);
486 
502 enum idmap_error_code sss_idmap_check_smb_sid_unix(struct sss_idmap_ctx *ctx,
503  struct dom_sid *smb_sid,
504  uint32_t id);
505 
520 enum idmap_error_code sss_idmap_unix_to_sid(struct sss_idmap_ctx *ctx,
521  uint32_t id,
522  char **sid);
523 
537 enum idmap_error_code sss_idmap_unix_to_dom_sid(struct sss_idmap_ctx *ctx,
538  uint32_t id,
539  struct sss_dom_sid **dom_sid);
540 
556 enum idmap_error_code sss_idmap_unix_to_bin_sid(struct sss_idmap_ctx *ctx,
557  uint32_t id,
558  uint8_t **bin_sid,
559  size_t *length);
560 
569 enum idmap_error_code sss_idmap_free(struct sss_idmap_ctx *ctx);
570 
580 enum idmap_error_code sss_idmap_free_sid(struct sss_idmap_ctx *ctx,
581  char *sid);
582 
592 enum idmap_error_code sss_idmap_free_dom_sid(struct sss_idmap_ctx *ctx,
593  struct sss_dom_sid *dom_sid);
594 
604 enum idmap_error_code sss_idmap_free_smb_sid(struct sss_idmap_ctx *ctx,
605  struct dom_sid *smb_sid);
606 
616 enum idmap_error_code sss_idmap_free_bin_sid(struct sss_idmap_ctx *ctx,
617  uint8_t *bin_sid);
618 
627 const char *idmap_error_string(enum idmap_error_code err);
628 
638 bool is_domain_sid(const char *str);
639 
659 enum idmap_error_code
660 sss_idmap_domain_has_algorithmic_mapping(struct sss_idmap_ctx *ctx,
661  const char *dom_sid,
662  bool *has_algorithmic_mapping);
663 
682 enum idmap_error_code
683 sss_idmap_domain_by_name_has_algorithmic_mapping(struct sss_idmap_ctx *ctx,
684  const char *dom_name,
685  bool *has_algorithmic_mapping);
686 
700 enum idmap_error_code sss_idmap_bin_sid_to_dom_sid(struct sss_idmap_ctx *ctx,
701  const uint8_t *bin_sid,
702  size_t length,
703  struct sss_dom_sid **dom_sid);
704 
718 enum idmap_error_code sss_idmap_bin_sid_to_sid(struct sss_idmap_ctx *ctx,
719  const uint8_t *bin_sid,
720  size_t length,
721  char **sid);
722 
736 enum idmap_error_code sss_idmap_dom_sid_to_bin_sid(struct sss_idmap_ctx *ctx,
737  struct sss_dom_sid *dom_sid,
738  uint8_t **bin_sid,
739  size_t *length);
740 
754 enum idmap_error_code sss_idmap_sid_to_bin_sid(struct sss_idmap_ctx *ctx,
755  const char *sid,
756  uint8_t **bin_sid,
757  size_t *length);
758 
771 enum idmap_error_code sss_idmap_dom_sid_to_sid(struct sss_idmap_ctx *ctx,
772  struct sss_dom_sid *dom_sid,
773  char **sid);
774 
787 enum idmap_error_code sss_idmap_sid_to_dom_sid(struct sss_idmap_ctx *ctx,
788  const char *sid,
789  struct sss_dom_sid **dom_sid);
790 
803 enum idmap_error_code sss_idmap_sid_to_smb_sid(struct sss_idmap_ctx *ctx,
804  const char *sid,
805  struct dom_sid **smb_sid);
806 
819 enum idmap_error_code sss_idmap_smb_sid_to_sid(struct sss_idmap_ctx *ctx,
820  struct dom_sid *smb_sid,
821  char **sid);
822 
835 enum idmap_error_code sss_idmap_dom_sid_to_smb_sid(struct sss_idmap_ctx *ctx,
836  struct sss_dom_sid *dom_sid,
837  struct dom_sid **smb_sid);
838 
851 enum idmap_error_code sss_idmap_smb_sid_to_dom_sid(struct sss_idmap_ctx *ctx,
852  struct dom_sid *smb_sid,
853  struct sss_dom_sid **dom_sid);
854 
868 enum idmap_error_code sss_idmap_bin_sid_to_smb_sid(struct sss_idmap_ctx *ctx,
869  const uint8_t *bin_sid,
870  size_t length,
871  struct dom_sid **smb_sid);
872 
886 enum idmap_error_code sss_idmap_smb_sid_to_bin_sid(struct sss_idmap_ctx *ctx,
887  struct dom_sid *smb_sid,
888  uint8_t **bin_sid,
889  size_t *length);
893 #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_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.
void *( idmap_alloc_func)(size_t size, void *pvt)
Typedef for memory allocation functions.
Definition: sss_idmap.h:93
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
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.
Structure for id ranges FIXME: this struct might change when it is clear how ranges are handled on th...
Definition: sss_idmap.h:101
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.