r61: - Implement first call in the winreg rpc server
authorJelmer Vernooij <jelmer@samba.org>
Mon, 5 Apr 2004 20:44:33 +0000 (20:44 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:50:41 +0000 (12:50 -0500)
- Add some initial implementation of the ldb backend
- More checks in the winreg torture test

source/lib/registry/reg_backend_ldb/reg_backend_ldb.c
source/lib/registry/reg_backend_rpc/reg_backend_rpc.c
source/rpc_server/handles.c
source/rpc_server/winreg/rpc_winreg.c
source/torture/rpc/winreg.c

index 75d5a9518749064ff7be9c15c3c4744831707884..afa60c5c4a1769234b223d151608c0d288fa2c06 100644 (file)
@@ -43,9 +43,25 @@ static BOOL ldb_close_registry(REG_HANDLE *h)
        return True;
 }
 
+static BOOL ldb_fetch_subkeys(REG_KEY *k, int *count, REG_KEY ***subkeys)
+{
+       ldb_search();
+}
+
 static REG_KEY *ldb_open_key(REG_HANDLE *h, const char *name)
 {
-       /* FIXME */
+       struct ldb_context *c = h->backend_data;
+       char *path;
+       struct ldb_message **msg;
+       REG_KEY *key = NULL;
+       (dn=key=Systems,
+       if(ldb_search(c, NULL, LDP_SCOPE_BASE, "", NULL,&msg) > 0) {
+               key = reg_key_new_abs(name, h, base);
+       }
+
+       ldap_search_free(c, msg);
+
+       return key;
 }
 
 static REG_OPS reg_backend_ldb = {
@@ -53,6 +69,7 @@ static REG_OPS reg_backend_ldb = {
        .open_registry = ldb_open_registry,
        .close_registry = ldb_close_registry,
        .open_key = ldb_open_key,
+       .fetch_subkeys = ldb_fetch_subkeys,
 };
 
 NTSTATUS reg_ldb_init(void)
index 84c3cb8aeec50c018cc832ca6d803a061d0d5d66..ad4d537f9b1456d437ac21a1be53b8951fb55aa9 100644 (file)
@@ -90,7 +90,7 @@ static BOOL rpc_open_registry(REG_HANDLE *h, const char *location, BOOL try_full
                     DCERPC_WINREG_UUID,
                     DCERPC_WINREG_VERSION,
                      lp_workgroup(),
-                     "jelwin", "dds");
+                     "tridge", "samba");
 
        if(!NT_STATUS_IS_OK(status)) return False;
 
index 043318c075c81d760b758afd2f3ff9d04f97033d..611dc42f76dedc1692bbf9676a3f1b85ff95ddf2 100644 (file)
@@ -32,7 +32,7 @@ struct dcesrv_handle *dcesrv_handle_new(struct dcesrv_connection *dce_conn,
        struct dcesrv_handle *h;
 
        mem_ctx = talloc_init("rpc handle type %d\n", handle_type);
-       if (!mem_ctx) {
+if (!mem_ctx) {
                return NULL;
        }
        h = talloc(mem_ctx, sizeof(*h));
index 2787c078477a5c48f269720b8651dcb61d109d21..e5658abb09433801726845b68b06082dda56cf86 100644 (file)
 
 #include "includes.h"
 
+enum handle_types { HTYPE_REGKEY, HTYPE_REGVAL };
+
+struct _privatedata {
+       REG_HANDLE *registry;
+};
+
+
+/* this function is called when the client disconnects the endpoint */
+static void winreg_unbind(struct dcesrv_connection *dc, const struct dcesrv_interface *di) 
+{
+       struct _privatedata *data = dc->private;
+       reg_free(data->registry);
+}
+
+static NTSTATUS winreg_bind(struct dcesrv_call_state *dc, const struct dcesrv_interface *di) 
+{
+       struct _privatedata *data;
+       data = talloc(dc->mem_ctx, sizeof(struct _privatedata));
+       data->registry = reg_open("nt4", "/home/aurelia/jelmer/NTUSER.DAT", False);
+       dc->conn->private = data;
+       return NT_STATUS_OK;
+}
+
+#define DCESRV_INTERFACE_WINREG_BIND winreg_bind
+#define DCESRV_INTERFACE_WINREG_UNBIND winreg_unbind
+
 /* 
   winreg_OpenHKCR 
 */
 static NTSTATUS winreg_OpenHKCR(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
                       struct winreg_OpenHKCR *r)
 {
+       
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
@@ -38,7 +65,20 @@ static NTSTATUS winreg_OpenHKCR(struct dcesrv_call_state *dce_call, TALLOC_CTX *
 static NTSTATUS winreg_OpenHKCU(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
                       struct winreg_OpenHKCU *r)
 {
-       return NT_STATUS_NOT_IMPLEMENTED;
+       struct _privatedata *data = dce_call->conn->private;
+       REG_KEY *k = reg_open_key(reg_get_root(data->registry), "\\HKEY_CURRENT_USER");
+
+       if(!k) {
+               r->out.result = WERR_BADFILE;
+       } else {
+               struct dcesrv_handle *h = dcesrv_handle_new(dce_call->conn, HTYPE_REGKEY);
+               h->data = k;
+               r->out.handle = &(h->wire_handle);
+       }
+
+       r->out.result = WERR_OK;
+
+       return NT_STATUS_OK;
 }
 
 
@@ -178,6 +218,11 @@ static NTSTATUS winreg_NotifyChangeKeyValue(struct dcesrv_call_state *dce_call,
 static NTSTATUS winreg_OpenKey(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
                       struct winreg_OpenKey *r)
 {
+       struct dcesrv_handle *h = dcesrv_handle_fetch(dce_call->conn, r->in.handle, HTYPE_REGKEY);
+       if(!h) {
+               return NT_STATUS_INVALID_HANDLE;
+       }
+       
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
index 23e3d2e779420e483454cf9ef94cad9d2e492ffb..41804d3302cced641b2dd96e42dc7d97445a225d 100644 (file)
@@ -80,6 +80,11 @@ static BOOL test_CreateKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                return False;
        }
 
+       if (!W_ERROR_IS_OK(r.out.result)) {
+               printf("CreateKey failed - %s\n", win_errstr(r.out.result));
+               return False;
+       }
+
        return True;
 }
 
@@ -166,6 +171,11 @@ static BOOL test_DeleteKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                return False;
        }
 
+       if (!W_ERROR_IS_OK(r.out.result)) {
+               printf("DeleteKey failed - %s\n", win_errstr(r.out.result));
+               return False;
+       }
+
        return True;
 }
 
@@ -413,7 +423,7 @@ typedef BOOL winreg_open_fn(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
 
 static BOOL test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, void *fn)
 {
-       struct policy_handle handle;
+       struct policy_handle handle, newhandle;
        BOOL ret = True;
        winreg_open_fn *open_fn = (winreg_open_fn *)fn;
 
@@ -435,11 +445,22 @@ static BOOL test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, void *fn)
                ret = False;
        }
 
+       if (!test_OpenKey(p, mem_ctx, &handle, "spottyfoot", &newhandle)) {
+               printf("CreateKey failed (OpenKey after Create didn't work)\n");
+               ret = False;
+       }
+
        if (!test_DeleteKey(p, mem_ctx, &handle, "spottyfoot")) {
                printf("DeleteKey failed\n");
                ret = False;
        }
 
+       if (test_OpenKey(p, mem_ctx, &handle, "spottyfoot", &newhandle)) {
+               printf("DeleteKey failed (OpenKey after Delete didn't work)\n");
+               ret = False;
+       }
+
+
        /* The HKCR hive has a very large fanout */
 
        if (open_fn == test_OpenHKCR) {