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

« back to all changes in this revision

Viewing changes to source4/lib/registry/rpc.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:
27
27
struct rpc_key {
28
28
        struct registry_key key;
29
29
        struct policy_handle pol;
30
 
        struct dcerpc_pipe *pipe;
31
 
 
 
30
        struct dcerpc_binding_handle *binding_handle;
32
31
        const char* classname;  
33
32
        uint32_t num_subkeys;
34
33
        uint32_t max_subkeylen;
43
42
struct rpc_registry_context {
44
43
        struct registry_context context;
45
44
        struct dcerpc_pipe *pipe;
 
45
        struct dcerpc_binding_handle *binding_handle;
46
46
};
47
47
 
48
48
static struct registry_operations reg_backend_rpc;
51
51
 * This is the RPC backend for the registry library.
52
52
 */
53
53
 
54
 
#define openhive(u) static WERROR open_ ## u(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *hnd) \
 
54
#define openhive(u) static WERROR open_ ## u(struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx, struct policy_handle *hnd) \
55
55
{ \
56
56
        struct winreg_Open ## u r; \
57
57
        NTSTATUS status; \
61
61
        r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; \
62
62
        r.out.handle = hnd;\
63
63
\
64
 
        status = dcerpc_winreg_Open ## u(p, mem_ctx, &r); \
 
64
        status = dcerpc_winreg_Open ## u ## _r(b, mem_ctx, &r); \
65
65
\
66
66
        if (!NT_STATUS_IS_OK(status)) { \
67
67
                DEBUG(1, ("OpenHive failed - %s\n", nt_errstr(status))); \
81
81
 
82
82
static struct {
83
83
        uint32_t hkey;
84
 
        WERROR (*open) (struct dcerpc_pipe *p, TALLOC_CTX *,
 
84
        WERROR (*open) (struct dcerpc_binding_handle *b, TALLOC_CTX *,
85
85
                        struct policy_handle *h);
86
86
} known_hives[] = {
87
87
        { HKEY_LOCAL_MACHINE, open_HKLM },
117
117
        }
118
118
 
119
119
        mykeydata = talloc_zero(ctx, struct rpc_key);
 
120
        W_ERROR_HAVE_NO_MEMORY(mykeydata);
120
121
        mykeydata->key.context = ctx;
121
 
        mykeydata->pipe = talloc_reference(mykeydata, rctx->pipe);
 
122
        mykeydata->binding_handle = rctx->binding_handle;
122
123
        mykeydata->num_values = -1;
123
124
        mykeydata->num_subkeys = -1;
124
125
        *k = (struct registry_key *)mykeydata;
125
 
        return known_hives[n].open(mykeydata->pipe, mykeydata, &(mykeydata->pol));
 
126
        return known_hives[n].open(mykeydata->binding_handle, mykeydata, &mykeydata->pol);
126
127
}
127
128
 
128
129
#if 0
160
161
        NTSTATUS status;
161
162
 
162
163
        mykeydata = talloc_zero(mem_ctx, struct rpc_key);
 
164
        W_ERROR_HAVE_NO_MEMORY(mykeydata);
163
165
        mykeydata->key.context = parentkeydata->key.context;
164
 
        mykeydata->pipe = talloc_reference(mykeydata, parentkeydata->pipe);
 
166
        mykeydata->binding_handle = parentkeydata->binding_handle;
165
167
        mykeydata->num_values = -1;
166
168
        mykeydata->num_subkeys = -1;
167
169
        *key = (struct registry_key *)mykeydata;
170
172
        ZERO_STRUCT(r);
171
173
        r.in.parent_handle = &parentkeydata->pol;
172
174
        r.in.keyname.name = name;
173
 
        r.in.unknown = 0x00000000;
 
175
        r.in.options = 0x00000000;
174
176
        r.in.access_mask = 0x02000000;
175
177
        r.out.handle = &mykeydata->pol;
176
178
 
177
 
        status = dcerpc_winreg_OpenKey(mykeydata->pipe, mem_ctx, &r);
 
179
        status = dcerpc_winreg_OpenKey_r(mykeydata->binding_handle, mem_ctx, &r);
178
180
 
179
181
        if (!NT_STATUS_IS_OK(status)) {
180
182
                DEBUG(1, ("OpenKey failed - %s\n", nt_errstr(status)));
212
214
        r.in.handle = &mykeydata->pol;
213
215
        r.in.enum_index = n;
214
216
        r.in.name = &name;
215
 
        r.in.type = type;
 
217
        r.in.type = (enum winreg_Type *) type;
216
218
        r.in.value = &value;
217
219
        r.in.size = &val_size;
218
220
        r.in.length = &zero;
219
221
        r.out.name = &name;
220
 
        r.out.type = type;
 
222
        r.out.type = (enum winreg_Type *) type;
221
223
        r.out.value = &value;
222
224
        r.out.size = &val_size;
223
225
        r.out.length = &zero;
224
226
 
225
 
        status = dcerpc_winreg_EnumValue(mykeydata->pipe, mem_ctx, &r);
 
227
        status = dcerpc_winreg_EnumValue_r(mykeydata->binding_handle, mem_ctx, &r);
226
228
 
227
229
        if (!NT_STATUS_IS_OK(status)) {
228
230
                DEBUG(1, ("EnumValue failed - %s\n", nt_errstr(status)));
229
231
                return ntstatus_to_werror(status);
230
232
        }
231
233
 
232
 
        *value_name = talloc_reference(mem_ctx, r.out.name->name);
 
234
        *value_name = talloc_steal(mem_ctx, r.out.name->name);
233
235
        *type = *(r.out.type);
234
236
        *data = data_blob_talloc(mem_ctx, r.out.value, *r.out.length);
235
237
 
261
263
        ZERO_STRUCT(r);
262
264
        r.in.handle = &mykeydata->pol;
263
265
        r.in.value_name = &name;
264
 
        r.in.type = type;
 
266
        r.in.type = (enum winreg_Type *) type;
265
267
        r.in.data = &value;
266
268
        r.in.data_size = &val_size;
267
269
        r.in.data_length = &zero;
268
 
        r.out.type = type;
 
270
        r.out.type = (enum winreg_Type *) type;
269
271
        r.out.data = &value;
270
272
        r.out.data_size = &val_size;
271
273
        r.out.data_length = &zero;
272
274
 
273
 
        status = dcerpc_winreg_QueryValue(mykeydata->pipe, mem_ctx, &r);
 
275
        status = dcerpc_winreg_QueryValue_r(mykeydata->binding_handle, mem_ctx, &r);
274
276
 
275
277
        if (!NT_STATUS_IS_OK(status)) {
276
278
                DEBUG(1, ("QueryValue failed - %s\n", nt_errstr(status)));
311
313
        r.out.keyclass = &classbuf;
312
314
        r.out.last_changed_time = &change_time;
313
315
 
314
 
        status = dcerpc_winreg_EnumKey(mykeydata->pipe, mem_ctx, &r);
 
316
        status = dcerpc_winreg_EnumKey_r(mykeydata->binding_handle, mem_ctx, &r);
315
317
 
316
318
        if (!NT_STATUS_IS_OK(status)) {
317
319
                DEBUG(1, ("EnumKey failed - %s\n", nt_errstr(status)));
319
321
        }
320
322
 
321
323
        if (name != NULL)
322
 
                *name = talloc_reference(mem_ctx, r.out.name->name);
 
324
                *name = talloc_steal(mem_ctx, r.out.name->name);
323
325
        if (keyclass != NULL)
324
 
                *keyclass = talloc_reference(mem_ctx, r.out.keyclass->name);
 
326
                *keyclass = talloc_steal(mem_ctx, r.out.keyclass->name);
325
327
        if (last_changed_time != NULL)
326
328
                *last_changed_time = *(r.out.last_changed_time);
327
329
 
329
331
}
330
332
 
331
333
static WERROR rpc_add_key(TALLOC_CTX *mem_ctx,
332
 
                          struct registry_key *parent, const char *name,
 
334
                          struct registry_key *parent, const char *path,
333
335
                          const char *key_class,
334
336
                          struct security_descriptor *sec,
335
337
                          struct registry_key **key)
342
344
 
343
345
        ZERO_STRUCT(r);
344
346
        r.in.handle = &parentkd->pol;
345
 
        r.in.name.name = name;
 
347
        r.in.name.name = path;
346
348
        r.in.keyclass.name = NULL;
347
349
        r.in.options = 0;
348
350
        r.in.access_mask = 0x02000000;
351
353
        r.out.new_handle = &rpck->pol;
352
354
        r.out.action_taken = NULL;
353
355
 
354
 
        status = dcerpc_winreg_CreateKey(parentkd->pipe, mem_ctx, &r);
 
356
        status = dcerpc_winreg_CreateKey_r(parentkd->binding_handle, mem_ctx, &r);
355
357
 
356
358
        if (!NT_STATUS_IS_OK(status)) {
357
359
                talloc_free(rpck);
359
361
                return ntstatus_to_werror(status);
360
362
        }
361
363
 
362
 
        rpck->pipe = talloc_reference(rpck, parentkd->pipe);
 
364
        rpck->binding_handle = parentkd->binding_handle;
363
365
        *key = (struct registry_key *)rpck;
364
366
 
365
367
        return r.out.result;
387
389
        r.out.secdescsize = &mykeydata->secdescsize;
388
390
        r.out.last_changed_time = &mykeydata->last_changed_time;
389
391
 
390
 
        status = dcerpc_winreg_QueryInfoKey(mykeydata->pipe, mem_ctx, &r);
 
392
        status = dcerpc_winreg_QueryInfoKey_r(mykeydata->binding_handle, mem_ctx, &r);
391
393
 
392
394
        if (!NT_STATUS_IS_OK(status)) {
393
395
                DEBUG(1, ("QueryInfoKey failed - %s\n", nt_errstr(status)));
394
396
                return ntstatus_to_werror(status);
395
397
        }
396
398
 
397
 
        mykeydata->classname = talloc_reference(mem_ctx, r.out.classname->name);
 
399
        mykeydata->classname = talloc_steal(mem_ctx, r.out.classname->name);
398
400
 
399
401
        return r.out.result;
400
402
}
401
403
 
402
 
static WERROR rpc_del_key(struct registry_key *parent, const char *name)
 
404
static WERROR rpc_del_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
 
405
                          const char *name)
403
406
{
404
407
        NTSTATUS status;
405
408
        struct rpc_key *mykeydata = talloc_get_type(parent, struct rpc_key);
406
409
        struct winreg_DeleteKey r;
407
 
        TALLOC_CTX *mem_ctx = talloc_init("del_key");
408
410
 
409
411
        ZERO_STRUCT(r);
410
412
        r.in.handle = &mykeydata->pol;
411
413
        r.in.key.name = name;
412
414
 
413
 
        status = dcerpc_winreg_DeleteKey(mykeydata->pipe, mem_ctx, &r);
414
 
 
415
 
        talloc_free(mem_ctx);
 
415
        status = dcerpc_winreg_DeleteKey_r(mykeydata->binding_handle, mem_ctx, &r);
416
416
 
417
417
        if (!NT_STATUS_IS_OK(status)) {
418
418
                DEBUG(1, ("DeleteKey failed - %s\n", nt_errstr(status)));
473
473
        .create_key = rpc_add_key,
474
474
        .delete_key = rpc_del_key,
475
475
        .get_key_info = rpc_get_info,
476
 
        .get_predefined_key = rpc_get_predefined_key,
477
476
};
478
477
 
479
478
_PUBLIC_ WERROR reg_open_remote(struct registry_context **ctx,
489
488
        dcerpc_init(lp_ctx);
490
489
 
491
490
        rctx = talloc(NULL, struct rpc_registry_context);
 
491
        W_ERROR_HAVE_NO_MEMORY(rctx);
492
492
 
493
493
        /* Default to local smbd if no connection is specified */
494
494
        if (!location) {
497
497
 
498
498
        status = dcerpc_pipe_connect(rctx /* TALLOC_CTX */,
499
499
                                     &p, location,
500
 
                                         &ndr_table_winreg,
 
500
                                     &ndr_table_winreg,
501
501
                                     credentials, ev, lp_ctx);
502
 
        rctx->pipe = p;
503
 
 
504
502
        if(NT_STATUS_IS_ERR(status)) {
505
503
                DEBUG(1, ("Unable to open '%s': %s\n", location,
506
504
                        nt_errstr(status)));
509
507
                return ntstatus_to_werror(status);
510
508
        }
511
509
 
 
510
        rctx->pipe = p;
 
511
        rctx->binding_handle = p->binding_handle;
 
512
 
512
513
        *ctx = (struct registry_context *)rctx;
513
514
        (*ctx)->ops = &reg_backend_rpc;
514
515