Changeset 988 for vendor/current/source3/lib/sharesec.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/lib/sharesec.c
r740 r988 22 22 #include "../libcli/security/security.h" 23 23 #include "../librpc/gen_ndr/ndr_security.h" 24 #include "dbwrap.h" 24 #include "dbwrap/dbwrap.h" 25 #include "dbwrap/dbwrap_open.h" 25 26 #include "util_tdb.h" 26 27 … … 41 42 static int delete_fn(struct db_record *rec, void *priv) 42 43 { 43 rec->delete_rec(rec);44 dbwrap_record_delete(rec); 44 45 return 0; 45 46 } … … 58 59 bool *p_upgrade_ok = (bool *)priv; 59 60 NTSTATUS status; 61 TDB_DATA key; 62 TDB_DATA value; 63 64 key = dbwrap_record_get_key(rec); 60 65 61 66 /* Is there space for a one character sharename ? */ 62 if ( rec->key.dsize <= prefix_len+2) {67 if (key.dsize <= prefix_len+2) { 63 68 return 0; 64 69 } 65 70 66 71 /* Does it start with the share key prefix ? */ 67 if (memcmp( rec->key.dptr, SHARE_SECURITY_DB_KEY_PREFIX_STR,72 if (memcmp(key.dptr, SHARE_SECURITY_DB_KEY_PREFIX_STR, 68 73 prefix_len) != 0) { 69 74 return 0; … … 71 76 72 77 /* Is it a null terminated string as a key ? */ 73 if ( rec->key.dptr[rec->key.dsize-1] != '\0') {78 if (key.dptr[key.dsize-1] != '\0') { 74 79 return 0; 75 80 } 76 81 77 82 /* Bytes after the prefix are the sharename string. */ 78 servicename = (char *)& rec->key.dptr[prefix_len];83 servicename = (char *)&key.dptr[prefix_len]; 79 84 c_servicename = canonicalize_servicename(talloc_tos(), servicename); 80 85 if (!c_servicename) { … … 89 94 90 95 /* Oops. Need to canonicalize name, delete old then store new. */ 91 status = rec->delete_rec(rec);96 status = dbwrap_record_delete(rec); 92 97 if (!NT_STATUS_IS_OK(status)) { 93 98 DEBUG(1, ("upgrade_v2_to_v3: Failed to delete secdesc for " 94 "%s: %s\n", rec->key.dptr, nt_errstr(status))); 99 "%s: %s\n", (const char *)key.dptr, 100 nt_errstr(status))); 95 101 TALLOC_FREE(c_servicename); 96 102 *p_upgrade_ok = false; … … 98 104 } else { 99 105 DEBUG(10, ("upgrade_v2_to_v3: deleted secdesc for " 100 "%s\n", rec->key.dptr));106 "%s\n", (const char *)key.dptr)); 101 107 } 102 108 … … 107 113 } 108 114 115 value = dbwrap_record_get_value(rec); 109 116 status = dbwrap_store(share_db, 110 117 string_term_tdb_data(newkey), 111 rec->value,118 value, 112 119 TDB_REPLACE); 113 120 … … 133 140 { 134 141 const char *vstring = "INFO/version"; 135 int32 vers_id; 136 int ret; 142 int32_t vers_id = 0; 137 143 bool upgrade_ok = true; 144 NTSTATUS status; 145 char *db_path; 138 146 139 147 if (share_db != NULL) { … … 141 149 } 142 150 143 share_db = db_open(NULL, state_path("share_info.tdb"), 0, 144 TDB_DEFAULT, O_RDWR|O_CREAT, 0600); 151 db_path = state_path("share_info.tdb"); 152 if (db_path == NULL) { 153 return false; 154 } 155 156 share_db = db_open(NULL, db_path, 0, 157 TDB_DEFAULT, O_RDWR|O_CREAT, 0600, 158 DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE); 145 159 if (share_db == NULL) { 146 160 DEBUG(0,("Failed to open share info database %s (%s)\n", 147 state_path("share_info.tdb"), strerror(errno) )); 161 db_path, strerror(errno))); 162 TALLOC_FREE(db_path); 148 163 return False; 149 164 } 150 151 vers_id = dbwrap_fetch_int32(share_db, vstring); 165 TALLOC_FREE(db_path); 166 167 status = dbwrap_fetch_int32_bystring(share_db, vstring, &vers_id); 168 if (!NT_STATUS_IS_OK(status)) { 169 vers_id = 0; 170 } 171 152 172 if (vers_id == SHARE_DATABASE_VERSION_V3) { 153 173 return true; 154 174 } 155 175 156 if ( share_db->transaction_start(share_db) != 0) {176 if (dbwrap_transaction_start(share_db) != 0) { 157 177 DEBUG(0, ("transaction_start failed\n")); 158 178 TALLOC_FREE(share_db); … … 160 180 } 161 181 162 vers_id = dbwrap_fetch_int32(share_db, vstring); 182 status = dbwrap_fetch_int32_bystring(share_db, vstring, &vers_id); 183 if (!NT_STATUS_IS_OK(status)) { 184 vers_id = 0; 185 } 186 163 187 if (vers_id == SHARE_DATABASE_VERSION_V3) { 164 188 /* 165 189 * Race condition 166 190 */ 167 if ( share_db->transaction_cancel(share_db)) {191 if (dbwrap_transaction_cancel(share_db)) { 168 192 smb_panic("transaction_cancel failed"); 169 193 } … … 177 201 /* Written on a bigendian machine with old fetch_int code. Save as le. */ 178 202 179 if (dbwrap_store_int32(share_db, vstring, 180 SHARE_DATABASE_VERSION_V2) != 0) { 181 DEBUG(0, ("dbwrap_store_int32 failed\n")); 203 status = dbwrap_store_int32_bystring( 204 share_db, vstring, SHARE_DATABASE_VERSION_V2); 205 if (!NT_STATUS_IS_OK(status)) { 206 DEBUG(0, ("dbwrap_store_int32 failed: %s\n", 207 nt_errstr(status))); 182 208 goto cancel; 183 209 } … … 186 212 187 213 if (vers_id != SHARE_DATABASE_VERSION_V2) { 188 ret = share_db->traverse(share_db, delete_fn, NULL);189 if ( ret < 0) {214 status = dbwrap_traverse(share_db, delete_fn, NULL, NULL); 215 if (!NT_STATUS_IS_OK(status)) { 190 216 DEBUG(0, ("traverse failed\n")); 191 217 goto cancel; 192 218 } 193 if (dbwrap_store_int32(share_db, vstring, 194 SHARE_DATABASE_VERSION_V2) != 0) { 195 DEBUG(0, ("dbwrap_store_int32 failed\n")); 219 status = dbwrap_store_int32_bystring( 220 share_db, vstring, SHARE_DATABASE_VERSION_V2); 221 if (!NT_STATUS_IS_OK(status)) { 222 DEBUG(0, ("dbwrap_store_int32 failed: %s\n", 223 nt_errstr(status))); 196 224 goto cancel; 197 225 } … … 200 228 /* Finally upgrade to version 3, with canonicalized sharenames. */ 201 229 202 ret = share_db->traverse(share_db, upgrade_v2_to_v3, &upgrade_ok);203 if ( ret < 0|| upgrade_ok == false) {230 status = dbwrap_traverse(share_db, upgrade_v2_to_v3, &upgrade_ok, NULL); 231 if (!NT_STATUS_IS_OK(status) || upgrade_ok == false) { 204 232 DEBUG(0, ("traverse failed\n")); 205 233 goto cancel; 206 234 } 207 if (dbwrap_store_int32(share_db, vstring, 208 SHARE_DATABASE_VERSION_V3) != 0) { 209 DEBUG(0, ("dbwrap_store_int32 failed\n")); 235 status = dbwrap_store_int32_bystring( 236 share_db, vstring, SHARE_DATABASE_VERSION_V3); 237 if (!NT_STATUS_IS_OK(status)) { 238 DEBUG(0, ("dbwrap_store_int32 failed: %s\n", 239 nt_errstr(status))); 210 240 goto cancel; 211 241 } 212 242 213 if ( share_db->transaction_commit(share_db) != 0) {243 if (dbwrap_transaction_commit(share_db) != 0) { 214 244 DEBUG(0, ("transaction_commit failed\n")); 215 245 return false; … … 219 249 220 250 cancel: 221 if ( share_db->transaction_cancel(share_db)) {251 if (dbwrap_transaction_cancel(share_db)) { 222 252 smb_panic("transaction_cancel failed"); 223 253 } … … 231 261 ********************************************************************/ 232 262 233 struct security_descriptor *get_share_security_default( TALLOC_CTX *ctx, size_t *psize, uint32 def_access)263 struct security_descriptor *get_share_security_default( TALLOC_CTX *ctx, size_t *psize, uint32_t def_access) 234 264 { 235 265 uint32_t sa; … … 237 267 struct security_acl *psa = NULL; 238 268 struct security_descriptor *psd = NULL; 239 uint32 spec_access = def_access;269 uint32_t spec_access = def_access; 240 270 241 271 se_map_generic(&spec_access, &file_generic_mapping); … … 288 318 TALLOC_FREE(c_servicename); 289 319 290 data = dbwrap_fetch_bystring(share_db, talloc_tos(), key);320 status = dbwrap_fetch_bystring(share_db, talloc_tos(), key, &data); 291 321 292 322 TALLOC_FREE(key); 293 323 294 if ( data.dptr == NULL) {324 if (!NT_STATUS_IS_OK(status)) { 295 325 return get_share_security_default(ctx, psize, 296 GENERIC_ALL_ACCESS);326 SEC_RIGHTS_DIR_ALL); 297 327 } 298 328 … … 302 332 303 333 if (!NT_STATUS_IS_OK(status)) { 304 DEBUG(0, ("unmarshall_sec_desc failed: %s\n",305 nt_errstr(status)));306 334 return get_share_security_default(ctx, psize, 307 GENERIC_ALL_ACCESS);335 SEC_RIGHTS_DIR_ALL); 308 336 } 309 337 … … 312 340 } else { 313 341 return get_share_security_default(ctx, psize, 314 GENERIC_ALL_ACCESS);342 SEC_RIGHTS_DIR_ALL); 315 343 } 316 344 … … 413 441 bool share_access_check(const struct security_token *token, 414 442 const char *sharename, 415 uint32 desired_access,443 uint32_t desired_access, 416 444 uint32_t *pgranted) 417 445 { 418 uint32 granted;446 uint32_t granted; 419 447 NTSTATUS status; 420 448 struct security_descriptor *psd = NULL; … … 424 452 425 453 if (!psd) { 426 return True; 427 } 428 429 status = se_access_check(psd, token, desired_access, &granted); 454 if (pgranted != NULL) { 455 *pgranted = desired_access; 456 } 457 return false; 458 } 459 460 status = se_file_access_check(psd, token, true, desired_access, &granted); 430 461 431 462 TALLOC_FREE(psd); … … 470 501 num_aces += count_chars(pacl,','); 471 502 472 ace_list = TALLOC_ARRAY(ctx, struct security_ace, num_aces);503 ace_list = talloc_array(ctx, struct security_ace, num_aces); 473 504 if (!ace_list) { 474 505 return False; … … 477 508 for (i = 0; i < num_aces; i++) { 478 509 uint32_t sa; 479 uint32 g_access;480 uint32 s_access;510 uint32_t g_access; 511 uint32_t s_access; 481 512 struct dom_sid sid; 482 513 char *sidstr;
Note:
See TracChangeset
for help on using the changeset viewer.