~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source3/libsmb/smb_share_modes.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
*/
26
26
 
27
27
#include "includes.h"
 
28
#include "system/filesys.h"
28
29
#include "smb_share_modes.h"
 
30
#include <tdb.h>
29
31
 
30
32
/* Database context handle. */
31
33
struct smbdb_ctx {
67
69
        memset(smb_db, '\0', sizeof(struct smbdb_ctx));
68
70
 
69
71
        smb_db->smb_tdb = tdb_open(db_path,
70
 
                                0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST,
 
72
                                0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
71
73
                                O_RDWR|O_CREAT,
72
74
                                0644);
73
75
 
155
157
 */
156
158
 
157
159
static void create_share_mode_entry(struct share_mode_entry *out,
158
 
                                const struct smb_share_mode_entry *in)
 
160
                                const struct smb_share_mode_entry *in,
 
161
                                uint32_t name_hash)
159
162
{
160
163
        memset(out, '\0', sizeof(struct share_mode_entry));
161
164
 
170
173
        out->id.extid = in->extid;
171
174
        out->uid = (uint32)geteuid();
172
175
        out->flags = 0;
 
176
        out->name_hash = name_hash;
173
177
}
174
178
 
175
179
/*
255
259
                return 0;
256
260
        }
257
261
 
258
 
        *p_delete_on_close = ld->u.s.delete_on_close;
 
262
        *p_delete_on_close = ld->u.s.num_delete_token_entries != 0;
259
263
        *pp_list = list;
260
264
        free(db_data.dptr);
261
265
        return list_num;
262
266
}
263
267
 
 
268
static uint32_t smb_name_hash(const char *sharepath, const char *filename, int *err)
 
269
{
 
270
        TDB_DATA key;
 
271
        char *fullpath = NULL;
 
272
        size_t sharepath_size = strlen(sharepath);
 
273
        size_t filename_size = strlen(filename);
 
274
        uint32_t name_hash;
 
275
 
 
276
        *err = 0;
 
277
        fullpath = (char *)malloc(sharepath_size + filename_size + 2);
 
278
        if (fullpath == NULL) {
 
279
                *err = 1;
 
280
                return 0;
 
281
        }
 
282
        memcpy(fullpath, sharepath, sharepath_size);
 
283
        fullpath[sharepath_size] = '/';
 
284
        memcpy(&fullpath[sharepath_size + 1], filename, filename_size + 1);
 
285
 
 
286
        key.dptr = (uint8_t *)fullpath;
 
287
        key.dsize = strlen(fullpath) + 1;
 
288
        name_hash = tdb_jenkins_hash(&key);
 
289
        free(fullpath);
 
290
        return name_hash;
 
291
}
 
292
 
264
293
/* 
265
294
 * Create an entry in the Samba share mode db.
266
295
 */
281
310
        struct share_mode_entry *shares = NULL;
282
311
        uint8 *new_data_p = NULL;
283
312
        size_t new_data_size = 0;
 
313
        int err = 0;
 
314
        uint32_t name_hash = smb_name_hash(sharepath, filename, &err);
 
315
 
 
316
        if (err) {
 
317
                return -1;
 
318
        }
284
319
 
285
320
        db_data = tdb_fetch(db_ctx->smb_tdb, locking_key);
286
321
        if (!db_data.dptr) {
296
331
                ld = (struct locking_data *)db_data.dptr;
297
332
                memset(ld, '\0', sizeof(struct locking_data));
298
333
                ld->u.s.num_share_mode_entries = 1;
299
 
                ld->u.s.delete_on_close = 0;
300
 
                ld->u.s.delete_token_size = 0;
 
334
                ld->u.s.num_delete_token_entries = 0;
301
335
                shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct locking_data));
302
 
                create_share_mode_entry(shares, new_entry);
 
336
                create_share_mode_entry(shares, new_entry, name_hash);
303
337
 
304
338
                memcpy(db_data.dptr + sizeof(struct locking_data) + sizeof(struct share_mode_entry),
305
339
                        sharepath,
338
372
        shares = (struct share_mode_entry *)(new_data_p + sizeof(struct locking_data) +
339
373
                        (orig_num_share_modes * sizeof(struct share_mode_entry)));
340
374
 
341
 
        create_share_mode_entry(shares, new_entry);
 
375
        create_share_mode_entry(shares, new_entry, name_hash);
342
376
 
343
377
        ld = (struct locking_data *)new_data_p;
344
378
        ld->u.s.num_share_mode_entries++;
345
379
 
346
 
        /* Append the original delete_token and filenames. */
 
380
        /* Append the original delete_tokens and filenames. */
347
381
        memcpy(new_data_p + sizeof(struct locking_data) + (ld->u.s.num_share_mode_entries * sizeof(struct share_mode_entry)),
348
382
                db_data.dptr + sizeof(struct locking_data) + (orig_num_share_modes * sizeof(struct share_mode_entry)),
349
383
                db_data.dsize - sizeof(struct locking_data) - (orig_num_share_modes * sizeof(struct share_mode_entry)));
460
494
                return tdb_delete(db_ctx->smb_tdb, locking_key);
461
495
        }
462
496
 
463
 
        /* Copy any delete token plus the terminating filenames. */
 
497
        /* Copy any delete tokens plus the terminating filenames. */
464
498
        remaining_ptr = db_data.dptr + sizeof(struct locking_data) + (orig_num_share_modes * sizeof(struct share_mode_entry));
465
499
        remaining_size = db_data.dsize - (remaining_ptr - db_data.dptr);
466
500
 
521
555
                }
522
556
 
523
557
                if (share_mode_entry_equal(set_entry, share)) {
524
 
                        create_share_mode_entry(share, new_entry);
 
558
                        create_share_mode_entry(share, new_entry, share->name_hash);
525
559
                        found_entry = 1;
526
560
                        break;
527
561
                }