Changeset 988 for vendor/current/source3/libsmb/smb_share_modes.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
-
vendor/current/source3/libsmb/smb_share_modes.c (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/libsmb/smb_share_modes.c
r740 r988 2 2 Samba share mode database library external interface library. 3 3 Used by non-Samba products needing access to the Samba share mode db. 4 5 6 7 8 9 10 11 4 12 5 13 Copyright (C) Jeremy Allison 2005 - 2006 … … 29 37 #include "smb_share_modes.h" 30 38 #include <tdb.h> 39 31 40 32 41 /* Database context handle. */ … … 40 49 #endif 41 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 42 80 int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, uint64_t dev, 43 81 uint64_t ino, uint64_t extid, … … 69 107 memset(smb_db, '\0', sizeof(struct smbdb_ctx)); 70 108 109 71 110 smb_db->smb_tdb = tdb_open(db_path, 72 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,73 O_RDWR|O_CREAT,74 0644);111 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, 112 O_RDWR|O_CREAT, 113 0644); 75 114 76 115 if (!smb_db->smb_tdb) { … … 106 145 lk->inode = (SMB_INO_T)ino; 107 146 lk->extid = extid; 108 ld.dptr = (uint8 *)lk;147 ld.dptr = (uint8 *)lk; 109 148 ld.dsize = sizeof(*lk); 110 149 return ld; … … 122 161 struct locking_key lk; 123 162 return tdb_chainlock(db_ctx->smb_tdb, get_locking_key(&lk, dev, ino, 124 extid)) ;163 extid)); 125 164 } 126 165 … … 131 170 { 132 171 struct locking_key lk; 133 return tdb_chainunlock(db_ctx->smb_tdb, 134 get_locking_key(&lk, dev, ino, extid)); 172 tdb_chainunlock(db_ctx->smb_tdb, 173 get_locking_key(&lk, dev, ino, extid)); 174 return 0; 135 175 } 136 176 … … 172 212 out->id.inode = in->ino; 173 213 out->id.extid = in->extid; 174 out->uid = (uint32 )geteuid();214 out->uid = (uint32)geteuid(); 175 215 out->flags = 0; 176 216 out->name_hash = name_hash; … … 201 241 *p_delete_on_close = 0; 202 242 203 db_data = tdb_fetch(db_ctx->smb_tdb, get_locking_key(&lk, dev, ino,204 extid));243 db_data = tdb_fetch(db_ctx->smb_tdb, 244 extid)); 205 245 if (!db_data.dptr) { 206 246 return 0; … … 234 274 if (kill(sharemodes_procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) { 235 275 continue; /* No longer exists. */ 236 }237 238 /* Ignore deferred open entries. */239 if (share->op_type == DEFERRED_OPEN_ENTRY) {240 continue;241 276 } 242 277 … … 268 303 static uint32_t smb_name_hash(const char *sharepath, const char *filename, int *err) 269 304 { 270 TDB_DATA key;271 305 char *fullpath = NULL; 272 306 size_t sharepath_size = strlen(sharepath); 273 307 size_t filename_size = strlen(filename); 274 308 uint32_t name_hash; 309 275 310 276 311 *err = 0; … … 284 319 memcpy(&fullpath[sharepath_size + 1], filename, filename_size + 1); 285 320 286 key .dptr = (uint8_t *)fullpath;287 key.dsize = strlen(fullpath) + 1;321 key 322 ; 288 323 name_hash = tdb_jenkins_hash(&key); 289 324 free(fullpath); … … 309 344 struct locking_data *ld = NULL; /* internal samba db state. */ 310 345 struct share_mode_entry *shares = NULL; 311 uint8 *new_data_p = NULL;346 uint8 *new_data_p = NULL; 312 347 size_t new_data_size = 0; 313 348 int err = 0; … … 321 356 if (!db_data.dptr) { 322 357 /* We must create the entry. */ 323 db_data.dptr = (uint8 *)malloc(358 db_data.dptr = (uint8 *)malloc( 324 359 sizeof(struct locking_data) + 325 360 sizeof(struct share_mode_entry) + … … 347 382 strlen(sharepath) + 1 + 348 383 strlen(filename) + 1; 349 if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_INSERT) == -1) {384 if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_INSERT) ) { 350 385 free(db_data.dptr); 351 386 return -1; … … 356 391 357 392 /* Entry exists, we must add a new entry. */ 358 new_data_p = (uint8 *)malloc(393 new_data_p = (uint8 *)malloc( 359 394 db_data.dsize + sizeof(struct share_mode_entry)); 360 395 if (!new_data_p) { … … 390 425 db_data.dsize = new_data_size; 391 426 392 if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) {427 if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) ) { 393 428 free(db_data.dptr); 394 429 return -1; … … 430 465 struct locking_data *ld = NULL; /* internal samba db state. */ 431 466 struct share_mode_entry *shares = NULL; 432 uint8 *new_data_p = NULL;467 uint8 *new_data_p = NULL; 433 468 size_t remaining_size = 0; 434 469 size_t i, num_share_modes; 435 const uint8 *remaining_ptr = NULL;470 const uint8 *remaining_ptr = NULL; 436 471 437 472 db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); … … 453 488 /* It's ours - just remove the entire record. */ 454 489 free(db_data.dptr); 455 return tdb_delete(db_ctx->smb_tdb, locking_key) ;490 return tdb_delete(db_ctx->smb_tdb, locking_key); 456 491 } 457 492 458 493 /* More than one - allocate a new record minus the one we'll delete. */ 459 new_data_p = (uint8 *)malloc(494 new_data_p = (uint8 *)malloc( 460 495 db_data.dsize - sizeof(struct share_mode_entry)); 461 496 if (!new_data_p) { … … 492 527 free(db_data.dptr); 493 528 free(new_data_p); 494 return tdb_delete(db_ctx->smb_tdb, locking_key) ;529 return tdb_delete(db_ctx->smb_tdb, locking_key); 495 530 } 496 531 … … 513 548 db_data.dsize = sizeof(struct locking_data) + (num_share_modes * sizeof(struct share_mode_entry)) + remaining_size; 514 549 515 if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) {550 if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) ) { 516 551 free(db_data.dptr); 517 552 return -1; … … 568 603 569 604 /* Save modified data. */ 570 if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) {605 if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) ) { 571 606 free(db_data.dptr); 572 607 return -1;
Note:
See TracChangeset
for help on using the changeset viewer.
