~ubuntu-branches/ubuntu/utopic/samba/utopic

« back to all changes in this revision

Viewing changes to source3/winbindd/winbindd_cache.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-02-21 09:06:34 UTC
  • mfrom: (0.39.23 sid)
  • Revision ID: package-import@ubuntu.com-20120221090634-svd7q7m33pfz0847
Tags: 2:3.6.3-1ubuntu1
* 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/fix-samba-printer-browsing.patch: No longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#undef DBGC_CLASS
39
39
#define DBGC_CLASS DBGC_WINBIND
40
40
 
41
 
#define WINBINDD_CACHE_VERSION 2
 
41
#define WINBINDD_CACHE_VER1 1 /* initial db version */
 
42
#define WINBINDD_CACHE_VER2 2 /* second version with timeouts for NDR entries */
 
43
 
 
44
#define WINBINDD_CACHE_VERSION WINBINDD_CACHE_VER2
42
45
#define WINBINDD_CACHE_VERSION_KEYSTR "WINBINDD_CACHE_VERSION"
43
46
 
44
47
extern struct winbindd_methods reconnect_methods;
4081
4084
        exit(47);
4082
4085
}
4083
4086
 
 
4087
static int wbcache_update_centry_fn(TDB_CONTEXT *tdb,
 
4088
                                    TDB_DATA key,
 
4089
                                    TDB_DATA data,
 
4090
                                    void *state)
 
4091
{
 
4092
        uint64_t ctimeout;
 
4093
        TDB_DATA blob;
 
4094
 
 
4095
        if (is_non_centry_key(key)) {
 
4096
                return 0;
 
4097
        }
 
4098
 
 
4099
        if (data.dptr == NULL || data.dsize == 0) {
 
4100
                if (tdb_delete(tdb, key) < 0) {
 
4101
                        DEBUG(0, ("tdb_delete for [%s] failed!\n",
 
4102
                                  key.dptr));
 
4103
                        return 1;
 
4104
                }
 
4105
        }
 
4106
 
 
4107
        /* add timeout to blob (uint64_t) */
 
4108
        blob.dsize = data.dsize + 8;
 
4109
 
 
4110
        blob.dptr = SMB_XMALLOC_ARRAY(uint8_t, blob.dsize);
 
4111
        if (blob.dptr == NULL) {
 
4112
                return 1;
 
4113
        }
 
4114
        memset(blob.dptr, 0, blob.dsize);
 
4115
 
 
4116
        /* copy status and seqnum */
 
4117
        memcpy(blob.dptr, data.dptr, 8);
 
4118
 
 
4119
        /* add timeout */
 
4120
        ctimeout = lp_winbind_cache_time() + time(NULL);
 
4121
        SBVAL(blob.dptr, 8, ctimeout);
 
4122
 
 
4123
        /* copy the rest */
 
4124
        memcpy(blob.dptr + 16, data.dptr + 8, data.dsize - 8);
 
4125
 
 
4126
        if (tdb_store(tdb, key, blob, TDB_REPLACE) < 0) {
 
4127
                DEBUG(0, ("tdb_store to update [%s] failed!\n",
 
4128
                          key.dptr));
 
4129
                SAFE_FREE(blob.dptr);
 
4130
                return 1;
 
4131
        }
 
4132
 
 
4133
        SAFE_FREE(blob.dptr);
 
4134
        return 0;
 
4135
}
 
4136
 
 
4137
static bool wbcache_upgrade_v1_to_v2(TDB_CONTEXT *tdb)
 
4138
{
 
4139
        int rc;
 
4140
 
 
4141
        DEBUG(1, ("Upgrade to version 2 of the winbindd_cache.tdb\n"));
 
4142
 
 
4143
        rc = tdb_traverse(tdb, wbcache_update_centry_fn, NULL);
 
4144
        if (rc < 0) {
 
4145
                return false;
 
4146
        }
 
4147
 
 
4148
        return true;
 
4149
}
 
4150
 
4084
4151
/***********************************************************************
4085
4152
 Try and validate every entry in the winbindd cache. If we fail here,
4086
4153
 delete the cache tdb and return non-zero.
4091
4158
        int ret = -1;
4092
4159
        const char *tdb_path = cache_path("winbindd_cache.tdb");
4093
4160
        TDB_CONTEXT *tdb = NULL;
 
4161
        uint32_t vers_id;
 
4162
        bool ok;
4094
4163
 
4095
4164
        DEBUG(10, ("winbindd_validate_cache: replacing panic function\n"));
4096
4165
        smb_panic_fn = validate_panic;
4097
4166
 
4098
 
 
4099
4167
        tdb = tdb_open_log(tdb_path, 
4100
4168
                           WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
4101
4169
                           TDB_INCOMPATIBLE_HASH |
4109
4177
                          "error opening/initializing tdb\n"));
4110
4178
                goto done;
4111
4179
        }
 
4180
 
 
4181
        /* Version check and upgrade code. */
 
4182
        if (!tdb_fetch_uint32(tdb, WINBINDD_CACHE_VERSION_KEYSTR, &vers_id)) {
 
4183
                DEBUG(10, ("Fresh database\n"));
 
4184
                tdb_store_uint32(tdb, WINBINDD_CACHE_VERSION_KEYSTR, WINBINDD_CACHE_VERSION);
 
4185
                vers_id = WINBINDD_CACHE_VERSION;
 
4186
        }
 
4187
 
 
4188
        if (vers_id != WINBINDD_CACHE_VERSION) {
 
4189
                if (vers_id == WINBINDD_CACHE_VER1) {
 
4190
                        ok = wbcache_upgrade_v1_to_v2(tdb);
 
4191
                        if (!ok) {
 
4192
                                DEBUG(10, ("winbindd_validate_cache: upgrade to version 2 failed.\n"));
 
4193
                                unlink(tdb_path);
 
4194
                                goto done;
 
4195
                        }
 
4196
 
 
4197
                        tdb_store_uint32(tdb,
 
4198
                                         WINBINDD_CACHE_VERSION_KEYSTR,
 
4199
                                         WINBINDD_CACHE_VERSION);
 
4200
                        vers_id = WINBINDD_CACHE_VER2;
 
4201
                }
 
4202
        }
 
4203
 
4112
4204
        tdb_close(tdb);
4113
4205
 
4114
4206
        ret = tdb_validate_and_backup(tdb_path, cache_traverse_validate_fn);