sss_idmap
1.14.2
|
00001 /* 00002 SSSD 00003 00004 ID-mapping library 00005 00006 Authors: 00007 Sumit Bose <sbose@redhat.com> 00008 00009 Copyright (C) 2012 Red Hat 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation; either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 This program is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 GNU General Public License for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with this program. If not, see <http://www.gnu.org/licenses/>. 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 00099 typedef enum idmap_error_code (*idmap_store_cb)(const char *dom_name, 00100 const char *dom_sid, 00101 const char *range_id, 00102 uint32_t min_id, 00103 uint32_t max_id, 00104 uint32_t first_rid, 00105 void *pvt); 00106 00112 struct sss_idmap_range { 00113 uint32_t min; 00114 uint32_t max; 00115 }; 00116 00120 struct sss_dom_sid; 00121 00125 struct sss_idmap_ctx; 00126 00132 struct dom_sid; 00133 00147 enum idmap_error_code sss_idmap_init(idmap_alloc_func *alloc_func, 00148 void *alloc_pvt, 00149 idmap_free_func *free_func, 00150 struct sss_idmap_ctx **ctx); 00151 00158 enum idmap_error_code 00159 sss_idmap_ctx_set_autorid(struct sss_idmap_ctx *ctx, bool use_autorid); 00160 00167 enum idmap_error_code 00168 sss_idmap_ctx_set_lower(struct sss_idmap_ctx *ctx, id_t lower); 00169 00176 enum idmap_error_code 00177 sss_idmap_ctx_set_upper(struct sss_idmap_ctx *ctx, id_t upper); 00178 00185 enum idmap_error_code 00186 sss_idmap_ctx_set_rangesize(struct sss_idmap_ctx *ctx, id_t rangesize); 00187 00195 enum idmap_error_code 00196 sss_idmap_ctx_set_extra_slice_init(struct sss_idmap_ctx *ctx, 00197 int extra_slice_init); 00198 00205 enum idmap_error_code 00206 sss_idmap_ctx_get_autorid(struct sss_idmap_ctx *ctx, bool *_autorid); 00207 00214 enum idmap_error_code 00215 sss_idmap_ctx_get_lower(struct sss_idmap_ctx *ctx, id_t *_lower); 00216 00223 enum idmap_error_code 00224 sss_idmap_ctx_get_upper(struct sss_idmap_ctx *ctx, id_t *_upper); 00225 00232 enum idmap_error_code 00233 sss_idmap_ctx_get_rangesize(struct sss_idmap_ctx *ctx, id_t *rangesize); 00234 00252 enum idmap_error_code sss_idmap_calculate_range(struct sss_idmap_ctx *ctx, 00253 const char *dom_sid, 00254 id_t *slice_num, 00255 struct sss_idmap_range *range); 00256 00274 enum idmap_error_code sss_idmap_add_domain(struct sss_idmap_ctx *ctx, 00275 const char *domain_name, 00276 const char *domain_sid, 00277 struct sss_idmap_range *range); 00278 00307 enum idmap_error_code sss_idmap_add_domain_ex(struct sss_idmap_ctx *ctx, 00308 const char *domain_name, 00309 const char *domain_sid, 00310 struct sss_idmap_range *range, 00311 const char *range_id, 00312 uint32_t rid, 00313 bool external_mapping); 00314 00347 enum idmap_error_code 00348 sss_idmap_add_auto_domain_ex(struct sss_idmap_ctx *ctx, 00349 const char *domain_name, 00350 const char *domain_sid, 00351 struct sss_idmap_range *range, 00352 const char *range_id, 00353 uint32_t rid, 00354 bool external_mapping, 00355 idmap_store_cb cb, 00356 void *pvt); 00357 00376 enum idmap_error_code sss_idmap_check_collision(struct sss_idmap_ctx *ctx, 00377 char *n_name, char *n_sid, 00378 struct sss_idmap_range *n_range, 00379 uint32_t n_first_rid, 00380 char *n_range_id, 00381 bool n_external_mapping); 00382 00410 enum idmap_error_code sss_idmap_check_collision_ex(const char *o_name, 00411 const char *o_sid, 00412 struct sss_idmap_range *o_range, 00413 uint32_t o_first_rid, 00414 const char *o_range_id, 00415 bool o_external_mapping, 00416 const char *n_name, 00417 const char *n_sid, 00418 struct sss_idmap_range *n_range, 00419 uint32_t n_first_rid, 00420 const char *n_range_id, 00421 bool n_external_mapping); 00436 enum idmap_error_code sss_idmap_sid_to_unix(struct sss_idmap_ctx *ctx, 00437 const char *sid, 00438 uint32_t *id); 00439 00454 enum idmap_error_code sss_idmap_dom_sid_to_unix(struct sss_idmap_ctx *ctx, 00455 struct sss_dom_sid *dom_sid, 00456 uint32_t *id); 00457 00473 enum idmap_error_code sss_idmap_bin_sid_to_unix(struct sss_idmap_ctx *ctx, 00474 uint8_t *bin_sid, 00475 size_t length, 00476 uint32_t *id); 00477 00492 enum idmap_error_code sss_idmap_smb_sid_to_unix(struct sss_idmap_ctx *ctx, 00493 struct dom_sid *smb_sid, 00494 uint32_t *id); 00495 00510 enum idmap_error_code sss_idmap_check_sid_unix(struct sss_idmap_ctx *ctx, 00511 const char *sid, 00512 uint32_t id); 00513 00528 enum idmap_error_code sss_idmap_check_dom_sid_unix(struct sss_idmap_ctx *ctx, 00529 struct sss_dom_sid *dom_sid, 00530 uint32_t id); 00531 00547 enum idmap_error_code sss_idmap_check_bin_sid_unix(struct sss_idmap_ctx *ctx, 00548 uint8_t *bin_sid, 00549 size_t length, 00550 uint32_t id); 00551 00567 enum idmap_error_code sss_idmap_check_smb_sid_unix(struct sss_idmap_ctx *ctx, 00568 struct dom_sid *smb_sid, 00569 uint32_t id); 00570 00585 enum idmap_error_code sss_idmap_unix_to_sid(struct sss_idmap_ctx *ctx, 00586 uint32_t id, 00587 char **sid); 00588 00602 enum idmap_error_code sss_idmap_unix_to_dom_sid(struct sss_idmap_ctx *ctx, 00603 uint32_t id, 00604 struct sss_dom_sid **dom_sid); 00605 00621 enum idmap_error_code sss_idmap_unix_to_bin_sid(struct sss_idmap_ctx *ctx, 00622 uint32_t id, 00623 uint8_t **bin_sid, 00624 size_t *length); 00625 00634 enum idmap_error_code sss_idmap_free(struct sss_idmap_ctx *ctx); 00635 00645 enum idmap_error_code sss_idmap_free_sid(struct sss_idmap_ctx *ctx, 00646 char *sid); 00647 00657 enum idmap_error_code sss_idmap_free_dom_sid(struct sss_idmap_ctx *ctx, 00658 struct sss_dom_sid *dom_sid); 00659 00669 enum idmap_error_code sss_idmap_free_smb_sid(struct sss_idmap_ctx *ctx, 00670 struct dom_sid *smb_sid); 00671 00681 enum idmap_error_code sss_idmap_free_bin_sid(struct sss_idmap_ctx *ctx, 00682 uint8_t *bin_sid); 00683 00692 const char *idmap_error_string(enum idmap_error_code err); 00693 00703 bool is_domain_sid(const char *str); 00704 00724 enum idmap_error_code 00725 sss_idmap_domain_has_algorithmic_mapping(struct sss_idmap_ctx *ctx, 00726 const char *dom_sid, 00727 bool *has_algorithmic_mapping); 00728 00747 enum idmap_error_code 00748 sss_idmap_domain_by_name_has_algorithmic_mapping(struct sss_idmap_ctx *ctx, 00749 const char *dom_name, 00750 bool *has_algorithmic_mapping); 00751 00765 enum idmap_error_code sss_idmap_bin_sid_to_dom_sid(struct sss_idmap_ctx *ctx, 00766 const uint8_t *bin_sid, 00767 size_t length, 00768 struct sss_dom_sid **dom_sid); 00769 00783 enum idmap_error_code sss_idmap_bin_sid_to_sid(struct sss_idmap_ctx *ctx, 00784 const uint8_t *bin_sid, 00785 size_t length, 00786 char **sid); 00787 00801 enum idmap_error_code sss_idmap_dom_sid_to_bin_sid(struct sss_idmap_ctx *ctx, 00802 struct sss_dom_sid *dom_sid, 00803 uint8_t **bin_sid, 00804 size_t *length); 00805 00819 enum idmap_error_code sss_idmap_sid_to_bin_sid(struct sss_idmap_ctx *ctx, 00820 const char *sid, 00821 uint8_t **bin_sid, 00822 size_t *length); 00823 00836 enum idmap_error_code sss_idmap_dom_sid_to_sid(struct sss_idmap_ctx *ctx, 00837 struct sss_dom_sid *dom_sid, 00838 char **sid); 00839 00852 enum idmap_error_code sss_idmap_sid_to_dom_sid(struct sss_idmap_ctx *ctx, 00853 const char *sid, 00854 struct sss_dom_sid **dom_sid); 00855 00868 enum idmap_error_code sss_idmap_sid_to_smb_sid(struct sss_idmap_ctx *ctx, 00869 const char *sid, 00870 struct dom_sid **smb_sid); 00871 00884 enum idmap_error_code sss_idmap_smb_sid_to_sid(struct sss_idmap_ctx *ctx, 00885 struct dom_sid *smb_sid, 00886 char **sid); 00887 00900 enum idmap_error_code sss_idmap_dom_sid_to_smb_sid(struct sss_idmap_ctx *ctx, 00901 struct sss_dom_sid *dom_sid, 00902 struct dom_sid **smb_sid); 00903 00916 enum idmap_error_code sss_idmap_smb_sid_to_dom_sid(struct sss_idmap_ctx *ctx, 00917 struct dom_sid *smb_sid, 00918 struct sss_dom_sid **dom_sid); 00919 00933 enum idmap_error_code sss_idmap_bin_sid_to_smb_sid(struct sss_idmap_ctx *ctx, 00934 const uint8_t *bin_sid, 00935 size_t length, 00936 struct dom_sid **smb_sid); 00937 00951 enum idmap_error_code sss_idmap_smb_sid_to_bin_sid(struct sss_idmap_ctx *ctx, 00952 struct dom_sid *smb_sid, 00953 uint8_t **bin_sid, 00954 size_t *length); 00958 #endif /* SSS_IDMAP_H_ */