s3:registry: move reg_objects.h to registry/ and use it only where needed
[kai/samba.git] / source3 / rpc_server / srv_ntsvcs_nt.c
index f2c85bbd3e42beefdf1dde6f25f9c118da24caca..f864dc175dd4c72baa85ab5fee6d23869d96a5be 100644 (file)
@@ -3,6 +3,7 @@
  *  RPC Pipe client / server routines
  *
  *  Copyright (C) Gerald (Jerry) Carter             2005.
+ *  Copyright (C) Guenther Deschner                 2008,2009.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -19,6 +20,9 @@
  */
 
 #include "includes.h"
+#include "../librpc/gen_ndr/srv_ntsvcs.h"
+#include "registry.h"
+#include "registry/reg_objects.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_RPC_SRV
@@ -50,8 +54,9 @@ WERROR _PNP_GetDeviceListSize(pipes_struct *p,
 {
        char *devicepath;
 
-       if (!r->in.devicename) {
-               return WERR_ACCESS_DENIED;
+       if ((r->in.flags & CM_GETIDLIST_FILTER_SERVICE) &&
+           (!r->in.devicename)) {
+               return WERR_CM_INVALID_POINTER;
        }
 
        if (!(devicepath = get_device_path(p->mem_ctx, r->in.devicename))) {
@@ -65,29 +70,49 @@ WERROR _PNP_GetDeviceListSize(pipes_struct *p,
        return WERR_OK;
 }
 
+/****************************************************************
+ _PNP_GetDeviceList
+****************************************************************/
 
-/********************************************************************
-********************************************************************/
-
-WERROR _ntsvcs_get_device_list( pipes_struct *p, NTSVCS_Q_GET_DEVICE_LIST *q_u, NTSVCS_R_GET_DEVICE_LIST *r_u )
+WERROR _PNP_GetDeviceList(pipes_struct *p,
+                         struct PNP_GetDeviceList *r)
 {
-       fstring device;
        char *devicepath;
+       uint32_t size = 0;
+       const char **multi_sz = NULL;
+       DATA_BLOB blob;
 
-       if ( !q_u->devicename )
-               return WERR_ACCESS_DENIED;
+       if ((r->in.flags & CM_GETIDLIST_FILTER_SERVICE) &&
+           (!r->in.filter)) {
+               return WERR_CM_INVALID_POINTER;
+       }
 
-       rpcstr_pull(device, q_u->devicename->buffer, sizeof(device), q_u->devicename->uni_str_len*2, 0);
+       if (!(devicepath = get_device_path(p->mem_ctx, r->in.filter))) {
+               return WERR_NOMEM;
+       }
 
-       if (!(devicepath = get_device_path(p->mem_ctx, device))) {
+       size = strlen(devicepath) + 2;
+
+       if (*r->in.length < size) {
+               return WERR_CM_BUFFER_SMALL;
+       }
+
+       multi_sz = talloc_zero_array(p->mem_ctx, const char *, 2);
+       if (!multi_sz) {
                return WERR_NOMEM;
        }
 
-       /* This has to be DOUBLE NULL terminated */
+       multi_sz[0] = devicepath;
 
-       init_unistr2( &r_u->devicepath, devicepath, UNI_STR_DBLTERMINATE );
-       TALLOC_FREE(devicepath);
-       r_u->needed = r_u->devicepath.uni_str_len;
+       if (!push_reg_multi_sz(multi_sz, &blob, multi_sz)) {
+               return WERR_NOMEM;
+       }
+
+       if (*r->in.length < blob.length/2) {
+               return WERR_CM_BUFFER_SMALL;
+       }
+
+       memcpy(r->out.buffer, blob.data, blob.length);
 
        return WERR_OK;
 }
@@ -100,8 +125,8 @@ WERROR _PNP_GetDeviceRegProp(pipes_struct *p,
                             struct PNP_GetDeviceRegProp *r)
 {
        char *ptr;
-       REGVAL_CTR *values;
-       REGISTRY_VALUE *val;
+       struct regval_ctr *values;
+       struct regval_blob *val;
 
        switch( r->in.property ) {
        case DEV_REGPROP_DESC:
@@ -125,22 +150,22 @@ WERROR _PNP_GetDeviceRegProp(pipes_struct *p,
                        return WERR_GENERAL_FAILURE;
                }
 
-               if (*r->in.buffer_size < val->size) {
-                       *r->out.needed = val->size;
+               if (*r->in.buffer_size < regval_size(val)) {
+                       *r->out.needed = regval_size(val);
                        *r->out.buffer_size = 0;
                        TALLOC_FREE( values );
                        return WERR_CM_BUFFER_SMALL;
                }
 
-               r->out.buffer = (uint8_t *)talloc_memdup(p->mem_ctx, val->data_p, val->size);
+               r->out.buffer = (uint8_t *)talloc_memdup(p->mem_ctx, regval_data_p(val), regval_size(val));
                TALLOC_FREE(values);
                if (!r->out.buffer) {
                        return WERR_NOMEM;
                }
 
                *r->out.reg_data_type = REG_SZ; /* always 1...tested using a remove device manager connection */
-               *r->out.buffer_size = val->size;
-               *r->out.needed = val->size;
+               *r->out.buffer_size = regval_size(val);
+               *r->out.needed = regval_size(val);
 
                break;
 
@@ -271,16 +296,6 @@ WERROR _PNP_EnumerateSubKeys(pipes_struct *p,
 /****************************************************************
 ****************************************************************/
 
-WERROR _PNP_GetDeviceList(pipes_struct *p,
-                         struct PNP_GetDeviceList *r)
-{
-       p->rng_fault_state = true;
-       return WERR_NOT_SUPPORTED;
-}
-
-/****************************************************************
-****************************************************************/
-
 WERROR _PNP_GetDepth(pipes_struct *p,
                     struct PNP_GetDepth *r)
 {