~ubuntu-branches/ubuntu/maverick/samba/maverick-security

« back to all changes in this revision

Viewing changes to source/registry/reg_objects.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2009-05-18 13:26:04 UTC
  • mfrom: (0.28.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090518132604-ebyuqimgymtr3h0k
Tags: 2:3.3.4-2ubuntu1
* Merge from debian unstable, remaining changes:
  + debian/patches/VERSION.patch:
    - setup SAMBA_VERSION_SUFFIX to Ubuntu.
  + 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/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted (LP: #312449)
  + debian/mksambapasswd.awk:
    - Do not add user with UID less than 1000 to smbpasswd.
  + debian/control:
    - Make libwbclient0 replace/conflict with hardy's likewise-open.
    - Don't build against ctdb.
    - Add suggests keyutils for smbfs. (LP: #300221)
  + debian/rules:
    - enable "native" PIE hardening.
    - remove --with-ctdb and --with-cluster-support=yes
  + Add ufw integration:
    - Created debian/samba.ufw profile.
    - debian/rules, debian/samba.dirs, debian/samba.files: install 
      profile
    - debian/control: have samba sugguest ufw.
* Dropped patches:
  + debian/patches/fix-upstream-bug-6186.patch: Merged upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#undef DBGC_CLASS
25
25
#define DBGC_CLASS DBGC_REGISTRY
26
26
 
 
27
struct regsubkey_ctr {
 
28
        uint32_t        num_subkeys;
 
29
        char            **subkeys;
 
30
        struct db_context *subkeys_hash;
 
31
        int seqnum;
 
32
};
 
33
 
27
34
/**********************************************************************
28
35
 
29
 
 Note that the REGSUB_CTR and REGVAL_CTR objects *must* be talloc()'d
30
 
 since the methods use the object pointer as the talloc context for
31
 
 internal private data.
 
36
 Note that the struct regsubkey_ctr and REGVAL_CTR objects *must* be
 
37
 talloc()'d since the methods use the object pointer as the talloc
 
38
 context for internal private data.
32
39
 
33
 
 There is no longer a regXXX_ctr_intit() and regXXX_ctr_destroy()
 
40
 There is no longer a regval_ctr_intit() and regval_ctr_destroy()
34
41
 pair of functions.  Simply TALLOC_ZERO_P() and TALLOC_FREE() the
35
42
 object.
36
43
 
37
44
 **********************************************************************/
38
45
 
 
46
WERROR regsubkey_ctr_init(TALLOC_CTX *mem_ctx, struct regsubkey_ctr **ctr)
 
47
{
 
48
        if (ctr == NULL) {
 
49
                return WERR_INVALID_PARAM;
 
50
        }
 
51
 
 
52
        *ctr = talloc_zero(mem_ctx, struct regsubkey_ctr);
 
53
        if (*ctr == NULL) {
 
54
                return WERR_NOMEM;
 
55
        }
 
56
 
 
57
        (*ctr)->subkeys_hash = db_open_rbt(*ctr);
 
58
        if ((*ctr)->subkeys_hash == NULL) {
 
59
                talloc_free(*ctr);
 
60
                return WERR_NOMEM;
 
61
        }
 
62
 
 
63
        return WERR_OK;
 
64
}
 
65
 
 
66
WERROR regsubkey_ctr_set_seqnum(struct regsubkey_ctr *ctr, int seqnum)
 
67
{
 
68
        if (ctr == NULL) {
 
69
                return WERR_INVALID_PARAM;
 
70
        }
 
71
 
 
72
        ctr->seqnum = seqnum;
 
73
 
 
74
        return WERR_OK;
 
75
}
 
76
 
 
77
int regsubkey_ctr_get_seqnum(struct regsubkey_ctr *ctr)
 
78
{
 
79
        if (ctr == NULL) {
 
80
                return -1;
 
81
        }
 
82
 
 
83
        return ctr->seqnum;
 
84
}
 
85
 
 
86
static WERROR regsubkey_ctr_hash_keyname(struct regsubkey_ctr *ctr,
 
87
                                         const char *keyname,
 
88
                                         uint32 idx)
 
89
{
 
90
        WERROR werr;
 
91
 
 
92
        werr = ntstatus_to_werror(dbwrap_store_bystring(ctr->subkeys_hash,
 
93
                                                keyname,
 
94
                                                make_tdb_data((uint8 *)&idx,
 
95
                                                              sizeof(idx)),
 
96
                                                TDB_REPLACE));
 
97
        if (!W_ERROR_IS_OK(werr)) {
 
98
                DEBUG(1, ("error hashing new key '%s' in container: %s\n",
 
99
                          keyname, dos_errstr(werr)));
 
100
        }
 
101
 
 
102
        return werr;
 
103
}
 
104
 
 
105
static WERROR regsubkey_ctr_unhash_keyname(struct regsubkey_ctr *ctr,
 
106
                                           const char *keyname)
 
107
{
 
108
        WERROR werr;
 
109
 
 
110
        werr = ntstatus_to_werror(dbwrap_delete_bystring(ctr->subkeys_hash,
 
111
                                  keyname));
 
112
        if (!W_ERROR_IS_OK(werr)) {
 
113
                DEBUG(1, ("error unhashing key '%s' in container: %s\n",
 
114
                          keyname, dos_errstr(werr)));
 
115
        }
 
116
 
 
117
        return werr;
 
118
}
 
119
 
 
120
static WERROR regsubkey_ctr_index_for_keyname(struct regsubkey_ctr *ctr,
 
121
                                              const char *keyname,
 
122
                                              uint32 *idx)
 
123
{
 
124
        TDB_DATA data;
 
125
 
 
126
        if ((ctr == NULL) || (keyname == NULL)) {
 
127
                return WERR_INVALID_PARAM;
 
128
        }
 
129
 
 
130
        data = dbwrap_fetch_bystring(ctr->subkeys_hash, ctr, keyname);
 
131
        if (data.dptr == NULL) {
 
132
                return WERR_NOT_FOUND;
 
133
        }
 
134
 
 
135
        if (data.dsize != sizeof(*idx)) {
 
136
                talloc_free(data.dptr);
 
137
                return WERR_INVALID_DATATYPE;
 
138
        }
 
139
 
 
140
        if (idx != NULL) {
 
141
                *idx = *(uint32 *)data.dptr;
 
142
        }
 
143
 
 
144
        talloc_free(data.dptr);
 
145
        return WERR_OK;
 
146
}
 
147
 
39
148
/***********************************************************************
40
149
 Add a new key to the array
41
150
 **********************************************************************/
42
151
 
43
 
WERROR regsubkey_ctr_addkey( REGSUBKEY_CTR *ctr, const char *keyname )
 
152
WERROR regsubkey_ctr_addkey( struct regsubkey_ctr *ctr, const char *keyname )
44
153
{
45
154
        char **newkeys;
 
155
        WERROR werr;
46
156
 
47
157
        if ( !keyname ) {
48
158
                return WERR_OK;
68
178
                 */
69
179
                return WERR_NOMEM;
70
180
        }
 
181
 
 
182
        werr = regsubkey_ctr_hash_keyname(ctr, keyname, ctr->num_subkeys);
 
183
        W_ERROR_NOT_OK_RETURN(werr);
 
184
 
71
185
        ctr->num_subkeys++;
72
186
 
73
187
        return WERR_OK;
77
191
 Delete a key from the array
78
192
 **********************************************************************/
79
193
 
80
 
int regsubkey_ctr_delkey( REGSUBKEY_CTR *ctr, const char *keyname )
 
194
WERROR regsubkey_ctr_delkey( struct regsubkey_ctr *ctr, const char *keyname )
81
195
{
82
 
        int i;
 
196
        WERROR werr;
 
197
        uint32 idx, j;
83
198
 
84
 
        if ( !keyname )
85
 
                return ctr->num_subkeys;
 
199
        if (keyname == NULL) {
 
200
                return WERR_INVALID_PARAM;
 
201
        }
86
202
 
87
203
        /* make sure the keyname is actually already there */
88
204
 
89
 
        for ( i=0; i<ctr->num_subkeys; i++ ) {
90
 
                if ( strequal( ctr->subkeys[i], keyname ) )
91
 
                        break;
92
 
        }
 
205
        werr = regsubkey_ctr_index_for_keyname(ctr, keyname, &idx);
 
206
        W_ERROR_NOT_OK_RETURN(werr);
93
207
 
94
 
        if ( i == ctr->num_subkeys )
95
 
                return ctr->num_subkeys;
 
208
        werr = regsubkey_ctr_unhash_keyname(ctr, keyname);
 
209
        W_ERROR_NOT_OK_RETURN(werr);
96
210
 
97
211
        /* update if we have any keys left */
98
212
        ctr->num_subkeys--;
99
 
        if ( i < ctr->num_subkeys )
100
 
                memmove(&ctr->subkeys[i], &ctr->subkeys[i+1],
101
 
                        sizeof(char*) * (ctr->num_subkeys-i));
102
 
 
103
 
        return ctr->num_subkeys;
 
213
        if (idx < ctr->num_subkeys) {
 
214
                memmove(&ctr->subkeys[idx], &ctr->subkeys[idx+1],
 
215
                        sizeof(char *) * (ctr->num_subkeys - idx));
 
216
 
 
217
                /* we have to re-hash rest of the array...  :-( */
 
218
                for (j = idx; j < ctr->num_subkeys; j++) {
 
219
                        werr = regsubkey_ctr_hash_keyname(ctr, ctr->subkeys[j], j);
 
220
                        W_ERROR_NOT_OK_RETURN(werr);
 
221
                }
 
222
        }
 
223
 
 
224
        return WERR_OK;
104
225
}
105
226
 
106
227
/***********************************************************************
107
228
 Check for the existance of a key
108
229
 **********************************************************************/
109
230
 
110
 
bool regsubkey_ctr_key_exists( REGSUBKEY_CTR *ctr, const char *keyname )
 
231
bool regsubkey_ctr_key_exists( struct regsubkey_ctr *ctr, const char *keyname )
111
232
{
112
 
        int     i;
 
233
        WERROR werr;
113
234
 
114
235
        if (!ctr->subkeys) {
115
236
                return False;
116
237
        }
117
238
 
118
 
        for ( i=0; i<ctr->num_subkeys; i++ ) {
119
 
                if ( strequal( ctr->subkeys[i],keyname ) )
120
 
                        return True;
 
239
        werr = regsubkey_ctr_index_for_keyname(ctr, keyname, NULL);
 
240
        if (!W_ERROR_IS_OK(werr)) {
 
241
                return false;
121
242
        }
122
243
 
123
 
        return False;
 
244
        return true;
124
245
}
125
246
 
126
247
/***********************************************************************
127
248
 How many keys does the container hold ?
128
249
 **********************************************************************/
129
250
 
130
 
int regsubkey_ctr_numkeys( REGSUBKEY_CTR *ctr )
 
251
int regsubkey_ctr_numkeys( struct regsubkey_ctr *ctr )
131
252
{
132
253
        return ctr->num_subkeys;
133
254
}
136
257
 Retreive a specific key string
137
258
 **********************************************************************/
138
259
 
139
 
char* regsubkey_ctr_specific_key( REGSUBKEY_CTR *ctr, uint32 key_index )
 
260
char* regsubkey_ctr_specific_key( struct regsubkey_ctr *ctr, uint32_t key_index )
140
261
{
141
262
        if ( ! (key_index < ctr->num_subkeys) )
142
263
                return NULL;