Changeset 745 for trunk/server/source3/winbindd/idmap_rid.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/winbindd/idmap_rid.c
r414 r745 21 21 #include "includes.h" 22 22 #include "winbindd.h" 23 #include "idmap.h" 24 #include "../libcli/security/dom_sid.h" 23 25 24 26 #undef DBGC_CLASS … … 26 28 27 29 struct idmap_rid_context { 28 const char *domain_name;29 uint32_t low_id;30 uint32_t high_id;31 30 uint32_t base_rid; 32 31 }; … … 37 36 *****************************************************************************/ 38 37 39 static NTSTATUS idmap_rid_initialize(struct idmap_domain *dom, 40 const char *params) 38 static NTSTATUS idmap_rid_initialize(struct idmap_domain *dom) 41 39 { 42 40 NTSTATUS ret; 43 41 struct idmap_rid_context *ctx; 44 42 char *config_option = NULL; 45 const char *range;46 uid_t low_uid = 0;47 uid_t high_uid = 0;48 gid_t low_gid = 0;49 gid_t high_gid = 0;50 43 51 if ( (ctx = TALLOC_ZERO_P(dom, struct idmap_rid_context)) == NULL ) { 44 ctx = TALLOC_ZERO_P(dom, struct idmap_rid_context); 45 if (ctx == NULL) { 52 46 DEBUG(0, ("Out of memory!\n")); 53 47 return NT_STATUS_NO_MEMORY; … … 61 55 } 62 56 63 range = lp_parm_const_string(-1, config_option, "range", NULL); 64 if ( !range || 65 (sscanf(range, "%u - %u", &ctx->low_id, &ctx->high_id) != 2) || 66 (ctx->low_id > ctx->high_id)) 67 { 68 ctx->low_id = 0; 69 ctx->high_id = 0; 70 } 57 ctx->base_rid = lp_parm_int(-1, config_option, "base_rid", 0); 71 58 72 /* lets see if the range is defined by the old idmap uid/idmap gid */73 if (!ctx->low_id && !ctx->high_id) {74 if (lp_idmap_uid(&low_uid, &high_uid)) {75 ctx->low_id = low_uid;76 ctx->high_id = high_uid;77 }78 79 if (lp_idmap_gid(&low_gid, &high_gid)) {80 if ((ctx->low_id != low_gid) ||81 (ctx->high_id != high_uid)) {82 DEBUG(1, ("ERROR: idmap uid range must match idmap gid range\n"));83 ret = NT_STATUS_UNSUCCESSFUL;84 goto failed;85 }86 }87 }88 89 if (!ctx->low_id || !ctx->high_id) {90 DEBUG(1, ("ERROR: Invalid configuration, ID range missing or invalid\n"));91 ret = NT_STATUS_UNSUCCESSFUL;92 goto failed;93 }94 95 ctx->base_rid = lp_parm_int(-1, config_option, "base_rid", 0);96 ctx->domain_name = talloc_strdup( ctx, dom->name );97 98 59 dom->private_data = ctx; 99 60 … … 106 67 } 107 68 108 static NTSTATUS idmap_rid_id_to_sid( TALLOC_CTX *memctx, struct idmap_rid_context *ctx, struct id_map *map)69 static NTSTATUS idmap_rid_id_to_sid(struct idmap_domain *dom, struct id_map *map) 109 70 { 110 struct winbindd_domain *domain; 71 struct winbindd_domain *domain; 72 struct idmap_rid_context *ctx; 73 74 ctx = talloc_get_type(dom->private_data, struct idmap_rid_context); 111 75 112 76 /* apply filters before checking */ 113 if ( (map->xid.id < ctx->low_id) || (map->xid.id > ctx->high_id)) {77 if (!idmap_unix_id_is_in_range(map->xid.id, dom)) { 114 78 DEBUG(5, ("Requested id (%u) out of range (%u - %u). Filtered!\n", 115 map->xid.id, ctx->low_id, ctx->high_id));79 map->xid.id, dom->low_id, dom->high_id)); 116 80 return NT_STATUS_NONE_MAPPED; 117 81 } 118 82 119 if ( (domain = find_domain_from_name_noinit(ctx->domain_name)) == NULL ) { 83 domain = find_domain_from_name_noinit(dom->name); 84 if (domain == NULL ) { 120 85 return NT_STATUS_NO_SUCH_DOMAIN; 121 86 } 122 123 sid_compose(map->sid, &domain->sid, map->xid.id - ctx->low_id + ctx->base_rid);87 88 sid_compose(map->sid, &domain->sid, map->xid.id - dom->low_id + ctx->base_rid); 124 89 125 90 /* We **really** should have some way of validating … … 136 101 **********************************/ 137 102 138 static NTSTATUS idmap_rid_sid_to_id( TALLOC_CTX *memctx, struct idmap_rid_context *ctx, struct id_map *map)103 static NTSTATUS idmap_rid_sid_to_id(struct idmap_domain *dom, struct id_map *map) 139 104 { 140 105 uint32_t rid; 106 struct idmap_rid_context *ctx; 107 108 ctx = talloc_get_type(dom->private_data, struct idmap_rid_context); 141 109 142 110 sid_peek_rid(map->sid, &rid); 143 map->xid.id = rid - ctx->base_rid + ctx->low_id;111 map->xid.id = rid - ctx->base_rid + dom->low_id; 144 112 145 113 /* apply filters before returning result */ 146 114 147 if ( (map->xid.id < ctx->low_id) || (map->xid.id > ctx->high_id)) {115 if (!idmap_unix_id_is_in_range(map->xid.id, dom)) { 148 116 DEBUG(5, ("Requested id (%u) out of range (%u - %u). Filtered!\n", 149 map->xid.id, ctx->low_id, ctx->high_id));117 map->xid.id, dom->low_id, dom->high_id)); 150 118 map->status = ID_UNMAPPED; 151 119 return NT_STATUS_NONE_MAPPED; 152 120 } 153 154 /* We **really** should have some way of validating155 the SID exists and is the correct type here. But156 that is a deficiency in the idmap_rid design. */157 121 158 122 map->status = ID_MAPPED; … … 167 131 static NTSTATUS idmap_rid_unixids_to_sids(struct idmap_domain *dom, struct id_map **ids) 168 132 { 169 struct idmap_rid_context *ridctx;170 TALLOC_CTX *ctx;171 133 NTSTATUS ret; 172 134 int i; … … 176 138 ids[i]->status = ID_UNKNOWN; 177 139 } 178 179 ridctx = talloc_get_type(dom->private_data, struct idmap_rid_context);180 181 ctx = talloc_new(dom);182 if ( ! ctx) {183 DEBUG(0, ("Out of memory!\n"));184 return NT_STATUS_NO_MEMORY;185 }186 140 187 141 for (i = 0; ids[i]; i++) { 188 142 189 ret = idmap_rid_id_to_sid( ctx, ridctx, ids[i]);143 ret = idmap_rid_id_to_sid(dom, ids[i]); 190 144 191 145 if (( ! NT_STATUS_IS_OK(ret)) && … … 196 150 } 197 151 198 talloc_free(ctx);199 152 return NT_STATUS_OK; 200 153 } … … 206 159 static NTSTATUS idmap_rid_sids_to_unixids(struct idmap_domain *dom, struct id_map **ids) 207 160 { 208 struct idmap_rid_context *ridctx;209 TALLOC_CTX *ctx;210 161 NTSTATUS ret; 211 162 int i; … … 215 166 ids[i]->status = ID_UNKNOWN; 216 167 } 217 218 ridctx = talloc_get_type(dom->private_data, struct idmap_rid_context);219 220 ctx = talloc_new(dom);221 if ( ! ctx) {222 DEBUG(0, ("Out of memory!\n"));223 return NT_STATUS_NO_MEMORY;224 }225 168 226 169 for (i = 0; ids[i]; i++) { 227 170 228 ret = idmap_rid_sid_to_id( ctx, ridctx, ids[i]);171 ret = idmap_rid_sid_to_id(dom, ids[i]); 229 172 230 173 if (( ! NT_STATUS_IS_OK(ret)) && … … 236 179 } 237 180 238 talloc_free(ctx);239 return NT_STATUS_OK;240 }241 242 static NTSTATUS idmap_rid_close(struct idmap_domain *dom)243 {244 if (dom->private_data) {245 TALLOC_FREE(dom->private_data);246 }247 181 return NT_STATUS_OK; 248 182 } … … 252 186 .unixids_to_sids = idmap_rid_unixids_to_sids, 253 187 .sids_to_unixids = idmap_rid_sids_to_unixids, 254 .close_fn = idmap_rid_close255 188 }; 256 189
Note:
See TracChangeset
for help on using the changeset viewer.