Registry server: Enhances commit "type" != NULL (when getting values)
[kai/samba-autobuild/.git] / source4 / rpc_server / winreg / rpc_winreg.c
index df965101cd1b067466ff17a5f4c0b870b5b42b53..30c1ed3db652f5f3264e5e54f4558da52d65ba91 100644 (file)
@@ -59,19 +59,18 @@ static WERROR dcesrv_winreg_openhive(struct dcesrv_call_state *dce_call,
 {
        struct registry_context *ctx = dce_call->context->private;
        struct dcesrv_handle *h;
-       WERROR error;
+       WERROR result;
 
        h = dcesrv_handle_new(dce_call->context, HTYPE_REGKEY);
 
-       error = reg_get_predefined_key(ctx, hkey,
+       result = reg_get_predefined_key(ctx, hkey,
                                       (struct registry_key **)&h->data);
-       if (!W_ERROR_IS_OK(error)) {
-               return error;
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
        }
-
        *outh = &h->wire_handle;
 
-       return error;
+       return result;
 }
 
 #define func_winreg_OpenHive(k,n) static WERROR dcesrv_winreg_Open ## k (struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct winreg_Open ## k *r) \
@@ -115,8 +114,8 @@ static WERROR dcesrv_winreg_CreateKey(struct dcesrv_call_state *dce_call,
                                      struct winreg_CreateKey *r)
 {
        struct dcesrv_handle *h, *newh;
-       WERROR error;
        struct security_descriptor sd;
+       WERROR result;
 
        DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
 
@@ -142,16 +141,16 @@ static WERROR dcesrv_winreg_CreateKey(struct dcesrv_call_state *dce_call,
                        }
                }
                
-               error = reg_key_add_name(newh, (struct registry_key *)h->data,
+               result = reg_key_add_name(newh, (struct registry_key *)h->data,
                                         r->in.name.name, NULL, r->in.secdesc?&sd:NULL,
                                         (struct registry_key **)&newh->data);
-               if (W_ERROR_IS_OK(error)) {
+               if (W_ERROR_IS_OK(result)) {
                        r->out.new_handle = &newh->wire_handle;
                } else {
                        talloc_free(newh);
                }
                
-               return error;
+               return result;
        default:
                return WERR_ACCESS_DENIED;
        }
@@ -188,7 +187,6 @@ static WERROR dcesrv_winreg_DeleteValue(struct dcesrv_call_state *dce_call,
                                        struct winreg_DeleteValue *r)
 {
        struct dcesrv_handle *h;
-       struct registry_key *key;
 
        DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
 
@@ -196,9 +194,7 @@ static WERROR dcesrv_winreg_DeleteValue(struct dcesrv_call_state *dce_call,
        {
        case SECURITY_SYSTEM:
        case SECURITY_ADMINISTRATOR:
-               key = h->data;
-               
-               return reg_del_value(key, r->in.value.name);
+               return reg_del_value((struct registry_key *)h->data, r->in.value.name);
        default:
                return WERR_ACCESS_DENIED;
        }
@@ -215,10 +211,11 @@ static WERROR dcesrv_winreg_EnumKey(struct dcesrv_call_state *dce_call,
        struct dcesrv_handle *h;
        const char *name, *classname;
        NTTIME last_mod;
+       WERROR result;
 
        DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
 
-       r->out.result = reg_key_get_subkey_by_index(mem_ctx,
+       result = reg_key_get_subkey_by_index(mem_ctx, 
                (struct registry_key *)h->data, r->in.enum_index,
                &name, &classname, &last_mod);
 
@@ -248,7 +245,7 @@ static WERROR dcesrv_winreg_EnumKey(struct dcesrv_call_state *dce_call,
        if (r->in.last_changed_time != NULL)
                r->out.last_changed_time = &last_mod;
 
-       return r->out.result;
+       return result;
 }
 
 
@@ -261,41 +258,24 @@ static WERROR dcesrv_winreg_EnumValue(struct dcesrv_call_state *dce_call,
 {
        struct dcesrv_handle *h;
        struct registry_key *key;
-       WERROR result;
        const char *data_name;
-       uint32_t data_type;
        DATA_BLOB data;
+       WERROR result;
 
        DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
 
        key = h->data;
 
-       result = reg_key_get_value_by_index(mem_ctx, key, r->in.enum_index,
-                                           &data_name,
-                                           &data_type, &data);
+       result = reg_key_get_value_by_index(mem_ctx, (struct registry_key *)h->data,
+               r->in.enum_index, &data_name, r->out.type, &data);
 
        if (!W_ERROR_IS_OK(result)) {
                /* if the lookup wasn't successful, send client query back */
                data_name = r->in.name->name;
-               data_type = *r->in.type;
                data.data = r->in.value;
                data.length = *r->in.length;
        }
 
-       /* the client can optionally pass a NULL for type, meaning they don't
-          want that back */
-       if (r->in.type != NULL) {
-               r->out.type = talloc(mem_ctx, enum winreg_Type);
-               *r->out.type = data_type;
-       }
-
-       /* check the client has enough room for the value */
-       if (r->in.value != NULL &&
-           r->in.size != NULL &&
-           data.length > *r->in.size) {
-               return WERR_MORE_DATA;
-       }
-
        /* and enough room for the name */
        if (r->in.name->size < 2*strlen_m_term(data_name)) {
                return WERR_MORE_DATA;
@@ -311,6 +291,13 @@ static WERROR dcesrv_winreg_EnumValue(struct dcesrv_call_state *dce_call,
        }
        r->out.name->size = r->in.name->size;
 
+       /* check the client has enough room for the value */
+       if (r->in.value != NULL &&
+           r->in.size != NULL &&
+           data.length > *r->in.size) {
+               return WERR_MORE_DATA;
+       }
+
        if (r->in.value != NULL) {
                r->out.value = data.data;
        }
@@ -432,9 +419,8 @@ static WERROR dcesrv_winreg_QueryInfoKey(struct dcesrv_call_state *dce_call,
                                         struct winreg_QueryInfoKey *r)
 {
        struct dcesrv_handle *h;
-       struct registry_key *k;
-       WERROR result;
        const char *classname = NULL;
+       WERROR result;
 
        DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
 
@@ -443,12 +429,10 @@ static WERROR dcesrv_winreg_QueryInfoKey(struct dcesrv_call_state *dce_call,
        case SECURITY_SYSTEM:
        case SECURITY_ADMINISTRATOR:
        case SECURITY_USER:
-               k = h->data;
-               
-               result = reg_key_get_info(mem_ctx, k, &classname, r->out.num_subkeys,
-                                      r->out.num_values, r->out.last_changed_time,
-                                      r->out.max_subkeylen, r->out.max_valnamelen, 
-                                      r->out.max_valbufsize);
+               result = reg_key_get_info(mem_ctx, (struct registry_key *)h->data,
+                        &classname, r->out.num_subkeys, r->out.num_values,
+                        r->out.last_changed_time, r->out.max_subkeylen,
+                        r->out.max_valnamelen, r->out.max_valbufsize);
 
                if (classname != NULL) {
                        r->out.classname->name = classname;
@@ -474,10 +458,8 @@ static WERROR dcesrv_winreg_QueryValue(struct dcesrv_call_state *dce_call,
                                       struct winreg_QueryValue *r)
 {
        struct dcesrv_handle *h;
-       struct registry_key *key;
-       WERROR result;
-       uint32_t value_type;
        DATA_BLOB value_data;
+       WERROR result;
 
        DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
 
@@ -486,25 +468,17 @@ static WERROR dcesrv_winreg_QueryValue(struct dcesrv_call_state *dce_call,
        case SECURITY_SYSTEM:
        case SECURITY_ADMINISTRATOR:
        case SECURITY_USER:
-               key = h->data;
-               
-               result = reg_key_get_value_by_name(mem_ctx, key, r->in.value_name.name,
-                                                  &value_type, &value_data);
+               result = reg_key_get_value_by_name(mem_ctx,
+                       (struct registry_key *)h->data, r->in.value_name.name,
+                                                  r->out.type, &value_data);
                
-
                if (!W_ERROR_IS_OK(result)) {
                        /* if the lookup wasn't successful, send client query back */
-                       value_type = *r->in.type;
                        value_data.data = r->in.data;
                        value_data.length = *r->in.length;
                }
 
                /* Just asking for the size of the buffer */
-               r->out.type = talloc(mem_ctx, uint32_t);
-               if (!r->out.type) {
-                       return WERR_NOMEM;
-               }
-               *r->out.type = value_type;
                r->out.length = talloc(mem_ctx, uint32_t);
                if (!r->out.length) {
                        return WERR_NOMEM;
@@ -577,21 +551,19 @@ static WERROR dcesrv_winreg_SetValue(struct dcesrv_call_state *dce_call,
                                     struct winreg_SetValue *r)
 {
        struct dcesrv_handle *h;
-       struct registry_key *key;
-       WERROR result;
        DATA_BLOB data;
+       WERROR result;
 
        DCESRV_PULL_HANDLE_FAULT(h, r->in.handle, HTYPE_REGKEY);
 
-       key = h->data;
-
        switch (security_session_user_level(dce_call->conn->auth_state.session_info))
        {
        case SECURITY_SYSTEM:
        case SECURITY_ADMINISTRATOR:
                data.data = r->in.data;
                data.length = r->in.size;
-               result = reg_val_set(key, r->in.name.name, r->in.type, data);
+               result = reg_val_set((struct registry_key *)h->data,
+                       r->in.name.name, r->in.type, data);
                return result;
        default:
                return WERR_ACCESS_DENIED;