sss_idmap
1.16.4
|
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 00091 IDMAP_ERR_LAST 00092 }; 00093 00097 typedef void *(idmap_alloc_func)(size_t size, void *pvt); 00098 typedef void (idmap_free_func)(void *ptr, void *pvt); 00099 00103 typedef enum idmap_error_code (*idmap_store_cb)(const char *dom_name, 00104 const char *dom_sid, 00105 const char *range_id, 00106 uint32_t min_id, 00107 uint32_t max_id, 00108 uint32_t first_rid, 00109 void *pvt); 00110 00116 struct sss_idmap_range { 00117 uint32_t min; 00118 uint32_t max; 00119 }; 00120 00124 struct sss_dom_sid; 00125 00129 struct sss_idmap_ctx; 00130 00136 struct dom_sid; 00137 00151 enum idmap_error_code sss_idmap_init(idmap_alloc_func *alloc_func, 00152 void *alloc_pvt, 00153 idmap_free_func *free_func, 00154 struct sss_idmap_ctx **ctx); 00155 00162 enum idmap_error_code 00163 sss_idmap_ctx_set_autorid(struct sss_idmap_ctx *ctx, bool use_autorid); 00164 00171 enum idmap_error_code 00172 sss_idmap_ctx_set_lower(struct sss_idmap_ctx *ctx, id_t lower); 00173 00180 enum idmap_error_code 00181 sss_idmap_ctx_set_upper(struct sss_idmap_ctx *ctx, id_t upper); 00182 00189 enum idmap_error_code 00190 sss_idmap_ctx_set_rangesize(struct sss_idmap_ctx *ctx, id_t rangesize); 00191 00199 enum idmap_error_code 00200 sss_idmap_ctx_set_extra_slice_init(struct sss_idmap_ctx *ctx, 00201 int extra_slice_init); 00202 00209 enum idmap_error_code 00210 sss_idmap_ctx_get_autorid(struct sss_idmap_ctx *ctx, bool *_autorid); 00211 00218 enum idmap_error_code 00219 sss_idmap_ctx_get_lower(struct sss_idmap_ctx *ctx, id_t *_lower); 00220 00227 enum idmap_error_code 00228 sss_idmap_ctx_get_upper(struct sss_idmap_ctx *ctx, id_t *_upper); 00229 00236 enum idmap_error_code 00237 sss_idmap_ctx_get_rangesize(struct sss_idmap_ctx *ctx, id_t *rangesize); 00238 00256 enum idmap_error_code sss_idmap_calculate_range(struct sss_idmap_ctx *ctx, 00257 const char *dom_sid, 00258 id_t *slice_num, 00259 struct sss_idmap_range *range); 00260 00278 enum idmap_error_code sss_idmap_add_domain(struct sss_idmap_ctx *ctx, 00279 const char *domain_name, 00280 const char *domain_sid, 00281 struct sss_idmap_range *range); 00282 00311 enum idmap_error_code sss_idmap_add_domain_ex(struct sss_idmap_ctx *ctx, 00312 const char *domain_name, 00313 const char *domain_sid, 00314 struct sss_idmap_range *range, 00315 const char *range_id, 00316 uint32_t rid, 00317 bool external_mapping); 00318 00351 enum idmap_error_code 00352 sss_idmap_add_auto_domain_ex(struct sss_idmap_ctx *ctx, 00353 const char *domain_name, 00354 const char *domain_sid, 00355 struct sss_idmap_range *range, 00356 const char *range_id, 00357 uint32_t rid, 00358 bool external_mapping, 00359 idmap_store_cb cb, 00360 void *pvt); 00361 00380 enum idmap_error_code sss_idmap_check_collision(struct sss_idmap_ctx *ctx, 00381 char *n_name, char *n_sid, 00382 struct sss_idmap_range *n_range, 00383 uint32_t n_first_rid, 00384 char *n_range_id, 00385 bool n_external_mapping); 00386 00414 enum idmap_error_code sss_idmap_check_collision_ex(const char *o_name, 00415 const char *o_sid, 00416 struct sss_idmap_range *o_range, 00417 uint32_t o_first_rid, 00418 const char *o_range_id, 00419 bool o_external_mapping, 00420 const char *n_name, 00421 const char *n_sid, 00422 struct sss_idmap_range *n_range, 00423 uint32_t n_first_rid, 00424 const char *n_range_id, 00425 bool n_external_mapping); 00440 enum idmap_error_code sss_idmap_sid_to_unix(struct sss_idmap_ctx *ctx, 00441 const char *sid, 00442 uint32_t *id); 00443 00458 enum idmap_error_code sss_idmap_dom_sid_to_unix(struct sss_idmap_ctx *ctx, 00459 struct sss_dom_sid *dom_sid, 00460 uint32_t *id); 00461 00477 enum idmap_error_code sss_idmap_bin_sid_to_unix(struct sss_idmap_ctx *ctx, 00478 uint8_t *bin_sid, 00479 size_t length, 00480 uint32_t *id); 00481 00496 enum idmap_error_code sss_idmap_smb_sid_to_unix(struct sss_idmap_ctx *ctx, 00497 struct dom_sid *smb_sid, 00498 uint32_t *id); 00499 00514 enum idmap_error_code sss_idmap_check_sid_unix(struct sss_idmap_ctx *ctx, 00515 const char *sid, 00516 uint32_t id); 00517 00532 enum idmap_error_code sss_idmap_check_dom_sid_unix(struct sss_idmap_ctx *ctx, 00533 struct sss_dom_sid *dom_sid, 00534 uint32_t id); 00535 00551 enum idmap_error_code sss_idmap_check_bin_sid_unix(struct sss_idmap_ctx *ctx, 00552 uint8_t *bin_sid, 00553 size_t length, 00554 uint32_t id); 00555 00571 enum idmap_error_code sss_idmap_check_smb_sid_unix(struct sss_idmap_ctx *ctx, 00572 struct dom_sid *smb_sid, 00573 uint32_t id); 00574 00589 enum idmap_error_code sss_idmap_unix_to_sid(struct sss_idmap_ctx *ctx, 00590 uint32_t id, 00591 char **sid); 00592 00606 enum idmap_error_code sss_idmap_unix_to_dom_sid(struct sss_idmap_ctx *ctx, 00607 uint32_t id, 00608 struct sss_dom_sid **dom_sid); 00609 00625 enum idmap_error_code sss_idmap_unix_to_bin_sid(struct sss_idmap_ctx *ctx, 00626 uint32_t id, 00627 uint8_t **bin_sid, 00628 size_t *length); 00629 00638 enum idmap_error_code sss_idmap_free(struct sss_idmap_ctx *ctx); 00639 00649 enum idmap_error_code sss_idmap_free_sid(struct sss_idmap_ctx *ctx, 00650 char *sid); 00651 00661 enum idmap_error_code sss_idmap_free_dom_sid(struct sss_idmap_ctx *ctx, 00662 struct sss_dom_sid *dom_sid); 00663 00673 enum idmap_error_code sss_idmap_free_smb_sid(struct sss_idmap_ctx *ctx, 00674 struct dom_sid *smb_sid); 00675 00685 enum idmap_error_code sss_idmap_free_bin_sid(struct sss_idmap_ctx *ctx, 00686 uint8_t *bin_sid); 00687 00696 const char *idmap_error_string(enum idmap_error_code err); 00697 00707 bool is_domain_sid(const char *str); 00708 00728 enum idmap_error_code 00729 sss_idmap_domain_has_algorithmic_mapping(struct sss_idmap_ctx *ctx, 00730 const char *dom_sid, 00731 bool *has_algorithmic_mapping); 00732 00751 enum idmap_error_code 00752 sss_idmap_domain_by_name_has_algorithmic_mapping(struct sss_idmap_ctx *ctx, 00753 const char *dom_name, 00754 bool *has_algorithmic_mapping); 00755 00769 enum idmap_error_code sss_idmap_bin_sid_to_dom_sid(struct sss_idmap_ctx *ctx, 00770 const uint8_t *bin_sid, 00771 size_t length, 00772 struct sss_dom_sid **dom_sid); 00773 00787 enum idmap_error_code sss_idmap_bin_sid_to_sid(struct sss_idmap_ctx *ctx, 00788 const uint8_t *bin_sid, 00789 size_t length, 00790 char **sid); 00791 00805 enum idmap_error_code sss_idmap_dom_sid_to_bin_sid(struct sss_idmap_ctx *ctx, 00806 struct sss_dom_sid *dom_sid, 00807 uint8_t **bin_sid, 00808 size_t *length); 00809 00823 enum idmap_error_code sss_idmap_sid_to_bin_sid(struct sss_idmap_ctx *ctx, 00824 const char *sid, 00825 uint8_t **bin_sid, 00826 size_t *length); 00827 00840 enum idmap_error_code sss_idmap_dom_sid_to_sid(struct sss_idmap_ctx *ctx, 00841 struct sss_dom_sid *dom_sid, 00842 char **sid); 00843 00856 enum idmap_error_code sss_idmap_sid_to_dom_sid(struct sss_idmap_ctx *ctx, 00857 const char *sid, 00858 struct sss_dom_sid **dom_sid); 00859 00872 enum idmap_error_code sss_idmap_sid_to_smb_sid(struct sss_idmap_ctx *ctx, 00873 const char *sid, 00874 struct dom_sid **smb_sid); 00875 00888 enum idmap_error_code sss_idmap_smb_sid_to_sid(struct sss_idmap_ctx *ctx, 00889 struct dom_sid *smb_sid, 00890 char **sid); 00891 00904 enum idmap_error_code sss_idmap_dom_sid_to_smb_sid(struct sss_idmap_ctx *ctx, 00905 struct sss_dom_sid *dom_sid, 00906 struct dom_sid **smb_sid); 00907 00920 enum idmap_error_code sss_idmap_smb_sid_to_dom_sid(struct sss_idmap_ctx *ctx, 00921 struct dom_sid *smb_sid, 00922 struct sss_dom_sid **dom_sid); 00923 00937 enum idmap_error_code sss_idmap_bin_sid_to_smb_sid(struct sss_idmap_ctx *ctx, 00938 const uint8_t *bin_sid, 00939 size_t length, 00940 struct dom_sid **smb_sid); 00941 00955 enum idmap_error_code sss_idmap_smb_sid_to_bin_sid(struct sss_idmap_ctx *ctx, 00956 struct dom_sid *smb_sid, 00957 uint8_t **bin_sid, 00958 size_t *length); 00962 #endif /* SSS_IDMAP_H_ */