s3:registry: move reg_api_regf prototypes to their own header file.
[amitay/samba.git] / source3 / rpc_server / srv_winreg_nt.c
index b4105a026b545aaa7c65b12d0619127dfe4cfeb0..298f33ab705bae4fc98be1877b56ce5faa7d3d23 100644 (file)
 #include "../librpc/gen_ndr/srv_winreg.h"
 #include "registry/reg_parse_prs.h"
 #include "registry.h"
+#include "registry/reg_api.h"
+#include "registry/reg_api_regf.h"
 #include "registry/reg_perfcount.h"
+#include "rpc_misc.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_RPC_SRV
@@ -237,8 +240,8 @@ WERROR _winreg_QueryValue(struct pipes_struct *p,
        struct registry_key *regkey = find_regkey_by_hnd( p, r->in.handle );
        prs_struct    prs_hkpd;
 
-       uint8_t *outbuf;
-       uint32_t outbuf_size;
+       uint8_t *outbuf = NULL;
+       uint32_t outbuf_size = 0;
 
        bool free_buf = False;
        bool free_prs = False;
@@ -403,7 +406,7 @@ WERROR _winreg_GetVersion(struct pipes_struct *p,
 WERROR _winreg_EnumKey(struct pipes_struct *p,
                       struct winreg_EnumKey *r)
 {
-       WERROR err;
+       WERROR err = WERR_OK;
        struct registry_key *key = find_regkey_by_hnd( p, r->in.handle );
 
        if ( !key )
@@ -430,10 +433,10 @@ WERROR _winreg_EnumKey(struct pipes_struct *p,
 WERROR _winreg_EnumValue(struct pipes_struct *p,
                         struct winreg_EnumValue *r)
 {
-       WERROR err;
+       WERROR err = WERR_OK;
        struct registry_key *key = find_regkey_by_hnd( p, r->in.handle );
-       char *valname;
-       struct registry_value *val;
+       char *valname = NULL;
+       struct registry_value *val = NULL;
 
        if ( !key )
                return WERR_BADFID;
@@ -519,8 +522,8 @@ WERROR _winreg_InitiateSystemShutdownEx(struct pipes_struct *p,
        fstring str_reason;
        fstring do_reboot;
        fstring f;
-       int ret;
-       bool can_shutdown;
+       int ret = -1;
+       bool can_shutdown = false;
 
        shutdown_script = talloc_strdup(p->mem_ctx, lp_shutdown_script());
        if (!shutdown_script) {
@@ -574,8 +577,7 @@ WERROR _winreg_InitiateSystemShutdownEx(struct pipes_struct *p,
                return WERR_NOMEM;
        }
 
-       can_shutdown = user_has_privileges( p->server_info->ptok,
-                                           &se_remote_shutdown );
+       can_shutdown = security_token_has_privilege(p->server_info->ptok, SEC_PRIV_REMOTE_SHUTDOWN);
 
        /* IF someone has privs, run the shutdown script as root. OTHERWISE run it as not root
           Take the error return from the script and provide it as the Windows return code. */
@@ -605,17 +607,14 @@ WERROR _winreg_InitiateSystemShutdownEx(struct pipes_struct *p,
 WERROR _winreg_AbortSystemShutdown(struct pipes_struct *p,
                                   struct winreg_AbortSystemShutdown *r)
 {
-       const char *abort_shutdown_script;
-       int ret;
-       bool can_shutdown;
-
-       abort_shutdown_script = lp_abort_shutdown_script();
+       const char *abort_shutdown_script = lp_abort_shutdown_script();
+       int ret = -1;
+       bool can_shutdown = false;
 
        if (!*abort_shutdown_script)
                return WERR_ACCESS_DENIED;
 
-       can_shutdown = user_has_privileges( p->server_info->ptok,
-                                           &se_remote_shutdown );
+       can_shutdown = security_token_has_privilege(p->server_info->ptok, SEC_PRIV_REMOTE_SHUTDOWN);
 
        /********** BEGIN SeRemoteShutdownPrivilege BLOCK **********/
 
@@ -643,7 +642,7 @@ static int validate_reg_filename(TALLOC_CTX *ctx, char **pp_fname )
        char *p = NULL;
        int num_services = lp_numservices();
        int snum = -1;
-       const char *share_path;
+       const char *share_path = NULL;
        char *fname = *pp_fname;
 
        /* convert to a unix path, stripping the C:\ along the way */
@@ -684,7 +683,7 @@ WERROR _winreg_RestoreKey(struct pipes_struct *p,
 {
        struct registry_key *regkey = find_regkey_by_hnd( p, r->in.handle );
        char *fname = NULL;
-       int             snum;
+       int snum = -1;
 
        if ( !regkey )
                return WERR_BADFID;
@@ -705,8 +704,9 @@ WERROR _winreg_RestoreKey(struct pipes_struct *p,
 
        /* user must posses SeRestorePrivilege for this this proceed */
 
-       if ( !user_has_privileges( p->server_info->ptok, &se_restore ) )
+       if ( !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_RESTORE)) {
                return WERR_ACCESS_DENIED;
+       }
 
        DEBUG(2,("_winreg_RestoreKey: Restoring [%s] from %s in share %s\n",
                 regkey->key->name, fname, lp_servicename(snum) ));
@@ -770,8 +770,8 @@ WERROR _winreg_CreateKey(struct pipes_struct *p,
                         struct winreg_CreateKey *r)
 {
        struct registry_key *parent = find_regkey_by_hnd(p, r->in.handle);
-       struct registry_key *new_key;
-       WERROR result;
+       struct registry_key *new_key = NULL;
+       WERROR result = WERR_OK;
 
        if ( !parent )
                return WERR_BADFID;
@@ -801,7 +801,7 @@ WERROR _winreg_SetValue(struct pipes_struct *p,
                        struct winreg_SetValue *r)
 {
        struct registry_key *key = find_regkey_by_hnd(p, r->in.handle);
-       struct registry_value *val;
+       struct registry_value *val = NULL;
 
        if ( !key )
                return WERR_BADFID;
@@ -859,10 +859,10 @@ WERROR _winreg_GetKeySecurity(struct pipes_struct *p,
                              struct winreg_GetKeySecurity *r)
 {
        struct registry_key *key = find_regkey_by_hnd(p, r->in.handle);
-       WERROR err;
-       struct security_descriptor *secdesc;
-       uint8 *data;
-       size_t len;
+       WERROR err = WERR_OK;
+       struct security_descriptor *secdesc = NULL;
+       uint8 *data = NULL;
+       size_t len = 0;
 
        if ( !key )
                return WERR_BADFID;
@@ -903,8 +903,8 @@ WERROR _winreg_SetKeySecurity(struct pipes_struct *p,
                              struct winreg_SetKeySecurity *r)
 {
        struct registry_key *key = find_regkey_by_hnd(p, r->in.handle);
-       struct security_descriptor *secdesc;
-       WERROR err;
+       struct security_descriptor *secdesc = NULL;
+       WERROR err = WERR_OK;
 
        if ( !key )
                return WERR_BADFID;
@@ -996,7 +996,7 @@ WERROR _winreg_QueryMultipleValues(struct pipes_struct *p,
                                   struct winreg_QueryMultipleValues *r)
 {
        struct winreg_QueryMultipleValues2 r2;
-       uint32_t needed;
+       uint32_t needed = 0;
 
        r2.in.key_handle        = r->in.key_handle;
        r2.in.values_in         = r->in.values_in;
@@ -1049,9 +1049,9 @@ WERROR _winreg_QueryMultipleValues2(struct pipes_struct *p,
        struct registry_value *vals = NULL;
        const char **names = NULL;
        uint32_t offset = 0, num_vals = 0;
-       DATA_BLOB result;
-       int i;
-       WERROR err;
+       DATA_BLOB result = data_blob_null;
+       int i = 0;
+       WERROR err = WERR_OK;
 
        if (!regkey) {
                return WERR_BADFID;