00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SSS_IDMAP_H_
00026 #define SSS_IDMAP_H_
00027
00028 #include <stdlib.h>
00029 #include <stdint.h>
00030 #include <stdbool.h>
00031 #include <sys/types.h>
00032
00033 #define DOM_SID_PREFIX "S-1-5-21-"
00034 #define DOM_SID_PREFIX_LEN (sizeof(DOM_SID_PREFIX) - 1)
00035
00046 enum idmap_error_code {
00048 IDMAP_SUCCESS = 0,
00049
00051 IDMAP_NOT_IMPLEMENTED,
00052
00054 IDMAP_ERROR,
00055
00057 IDMAP_OUT_OF_MEMORY,
00058
00060 IDMAP_NO_DOMAIN,
00061
00063 IDMAP_CONTEXT_INVALID,
00064
00066 IDMAP_SID_INVALID,
00067
00069 IDMAP_SID_UNKNOWN,
00070
00072 IDMAP_NO_RANGE,
00073
00075 IDMAP_BUILTIN_SID,
00076
00078 IDMAP_OUT_OF_SLICES,
00079
00081 IDMAP_COLLISION,
00082
00084 IDMAP_EXTERNAL,
00085
00087 IDMAP_NAME_UNKNOWN
00088 };
00089
00093 typedef void *(idmap_alloc_func)(size_t size, void *pvt);
00094 typedef void (idmap_free_func)(void *ptr, void *pvt);
00095
00101 struct sss_idmap_range {
00102 uint32_t min;
00103 uint32_t max;
00104 };
00105
00109 struct sss_dom_sid;
00110
00114 struct sss_idmap_ctx;
00115
00121 struct dom_sid;
00122
00136 enum idmap_error_code sss_idmap_init(idmap_alloc_func *alloc_func,
00137 void *alloc_pvt,
00138 idmap_free_func *free_func,
00139 struct sss_idmap_ctx **ctx);
00140
00147 enum idmap_error_code
00148 sss_idmap_ctx_set_autorid(struct sss_idmap_ctx *ctx, bool use_autorid);
00149
00156 enum idmap_error_code
00157 sss_idmap_ctx_set_lower(struct sss_idmap_ctx *ctx, id_t lower);
00158
00165 enum idmap_error_code
00166 sss_idmap_ctx_set_upper(struct sss_idmap_ctx *ctx, id_t upper);
00167
00174 enum idmap_error_code
00175 sss_idmap_ctx_set_rangesize(struct sss_idmap_ctx *ctx, id_t rangesize);
00176
00183 enum idmap_error_code
00184 sss_idmap_ctx_get_autorid(struct sss_idmap_ctx *ctx, bool *_autorid);
00185
00192 enum idmap_error_code
00193 sss_idmap_ctx_get_lower(struct sss_idmap_ctx *ctx, id_t *_lower);
00194
00201 enum idmap_error_code
00202 sss_idmap_ctx_get_upper(struct sss_idmap_ctx *ctx, id_t *_upper);
00203
00210 enum idmap_error_code
00211 sss_idmap_ctx_get_rangesize(struct sss_idmap_ctx *ctx, id_t *rangesize);
00212
00230 enum idmap_error_code sss_idmap_calculate_range(struct sss_idmap_ctx *ctx,
00231 const char *dom_sid,
00232 id_t *slice_num,
00233 struct sss_idmap_range *range);
00234
00252 enum idmap_error_code sss_idmap_add_domain(struct sss_idmap_ctx *ctx,
00253 const char *domain_name,
00254 const char *domain_sid,
00255 struct sss_idmap_range *range);
00256
00285 enum idmap_error_code sss_idmap_add_domain_ex(struct sss_idmap_ctx *ctx,
00286 const char *domain_name,
00287 const char *domain_sid,
00288 struct sss_idmap_range *range,
00289 const char *range_id,
00290 uint32_t rid,
00291 bool external_mapping);
00292
00311 enum idmap_error_code sss_idmap_check_collision(struct sss_idmap_ctx *ctx,
00312 char *n_name, char *n_sid,
00313 struct sss_idmap_range *n_range,
00314 uint32_t n_first_rid,
00315 char *n_range_id,
00316 bool n_external_mapping);
00317
00345 enum idmap_error_code sss_idmap_check_collision_ex(const char *o_name,
00346 const char *o_sid,
00347 struct sss_idmap_range *o_range,
00348 uint32_t o_first_rid,
00349 const char *o_range_id,
00350 bool o_external_mapping,
00351 const char *n_name,
00352 const char *n_sid,
00353 struct sss_idmap_range *n_range,
00354 uint32_t n_first_rid,
00355 const char *n_range_id,
00356 bool n_external_mapping);
00371 enum idmap_error_code sss_idmap_sid_to_unix(struct sss_idmap_ctx *ctx,
00372 const char *sid,
00373 uint32_t *id);
00374
00389 enum idmap_error_code sss_idmap_dom_sid_to_unix(struct sss_idmap_ctx *ctx,
00390 struct sss_dom_sid *dom_sid,
00391 uint32_t *id);
00392
00408 enum idmap_error_code sss_idmap_bin_sid_to_unix(struct sss_idmap_ctx *ctx,
00409 uint8_t *bin_sid,
00410 size_t length,
00411 uint32_t *id);
00412
00427 enum idmap_error_code sss_idmap_smb_sid_to_unix(struct sss_idmap_ctx *ctx,
00428 struct dom_sid *smb_sid,
00429 uint32_t *id);
00430
00445 enum idmap_error_code sss_idmap_check_sid_unix(struct sss_idmap_ctx *ctx,
00446 const char *sid,
00447 uint32_t id);
00448
00463 enum idmap_error_code sss_idmap_check_dom_sid_unix(struct sss_idmap_ctx *ctx,
00464 struct sss_dom_sid *dom_sid,
00465 uint32_t id);
00466
00482 enum idmap_error_code sss_idmap_check_bin_sid_unix(struct sss_idmap_ctx *ctx,
00483 uint8_t *bin_sid,
00484 size_t length,
00485 uint32_t id);
00486
00502 enum idmap_error_code sss_idmap_check_smb_sid_unix(struct sss_idmap_ctx *ctx,
00503 struct dom_sid *smb_sid,
00504 uint32_t id);
00505
00520 enum idmap_error_code sss_idmap_unix_to_sid(struct sss_idmap_ctx *ctx,
00521 uint32_t id,
00522 char **sid);
00523
00537 enum idmap_error_code sss_idmap_unix_to_dom_sid(struct sss_idmap_ctx *ctx,
00538 uint32_t id,
00539 struct sss_dom_sid **dom_sid);
00540
00556 enum idmap_error_code sss_idmap_unix_to_bin_sid(struct sss_idmap_ctx *ctx,
00557 uint32_t id,
00558 uint8_t **bin_sid,
00559 size_t *length);
00560
00569 enum idmap_error_code sss_idmap_free(struct sss_idmap_ctx *ctx);
00570
00580 enum idmap_error_code sss_idmap_free_sid(struct sss_idmap_ctx *ctx,
00581 char *sid);
00582
00592 enum idmap_error_code sss_idmap_free_dom_sid(struct sss_idmap_ctx *ctx,
00593 struct sss_dom_sid *dom_sid);
00594
00604 enum idmap_error_code sss_idmap_free_smb_sid(struct sss_idmap_ctx *ctx,
00605 struct dom_sid *smb_sid);
00606
00616 enum idmap_error_code sss_idmap_free_bin_sid(struct sss_idmap_ctx *ctx,
00617 uint8_t *bin_sid);
00618
00627 const char *idmap_error_string(enum idmap_error_code err);
00628
00638 bool is_domain_sid(const char *str);
00639
00659 enum idmap_error_code
00660 sss_idmap_domain_has_algorithmic_mapping(struct sss_idmap_ctx *ctx,
00661 const char *dom_sid,
00662 bool *has_algorithmic_mapping);
00663
00682 enum idmap_error_code
00683 sss_idmap_domain_by_name_has_algorithmic_mapping(struct sss_idmap_ctx *ctx,
00684 const char *dom_name,
00685 bool *has_algorithmic_mapping);
00686
00700 enum idmap_error_code sss_idmap_bin_sid_to_dom_sid(struct sss_idmap_ctx *ctx,
00701 const uint8_t *bin_sid,
00702 size_t length,
00703 struct sss_dom_sid **dom_sid);
00704
00718 enum idmap_error_code sss_idmap_bin_sid_to_sid(struct sss_idmap_ctx *ctx,
00719 const uint8_t *bin_sid,
00720 size_t length,
00721 char **sid);
00722
00736 enum idmap_error_code sss_idmap_dom_sid_to_bin_sid(struct sss_idmap_ctx *ctx,
00737 struct sss_dom_sid *dom_sid,
00738 uint8_t **bin_sid,
00739 size_t *length);
00740
00754 enum idmap_error_code sss_idmap_sid_to_bin_sid(struct sss_idmap_ctx *ctx,
00755 const char *sid,
00756 uint8_t **bin_sid,
00757 size_t *length);
00758
00771 enum idmap_error_code sss_idmap_dom_sid_to_sid(struct sss_idmap_ctx *ctx,
00772 struct sss_dom_sid *dom_sid,
00773 char **sid);
00774
00787 enum idmap_error_code sss_idmap_sid_to_dom_sid(struct sss_idmap_ctx *ctx,
00788 const char *sid,
00789 struct sss_dom_sid **dom_sid);
00790
00803 enum idmap_error_code sss_idmap_sid_to_smb_sid(struct sss_idmap_ctx *ctx,
00804 const char *sid,
00805 struct dom_sid **smb_sid);
00806
00819 enum idmap_error_code sss_idmap_smb_sid_to_sid(struct sss_idmap_ctx *ctx,
00820 struct dom_sid *smb_sid,
00821 char **sid);
00822
00835 enum idmap_error_code sss_idmap_dom_sid_to_smb_sid(struct sss_idmap_ctx *ctx,
00836 struct sss_dom_sid *dom_sid,
00837 struct dom_sid **smb_sid);
00838
00851 enum idmap_error_code sss_idmap_smb_sid_to_dom_sid(struct sss_idmap_ctx *ctx,
00852 struct dom_sid *smb_sid,
00853 struct sss_dom_sid **dom_sid);
00854
00868 enum idmap_error_code sss_idmap_bin_sid_to_smb_sid(struct sss_idmap_ctx *ctx,
00869 const uint8_t *bin_sid,
00870 size_t length,
00871 struct dom_sid **smb_sid);
00872
00886 enum idmap_error_code sss_idmap_smb_sid_to_bin_sid(struct sss_idmap_ctx *ctx,
00887 struct dom_sid *smb_sid,
00888 uint8_t **bin_sid,
00889 size_t *length);
00893 #endif