s3:netlookup: make use of cli_credentials_init_anon()
[bbaumbach/samba-autobuild/.git] / source3 / utils / net_rpc_registry.c
index 9445e09c7d214f7390e4ecffcbaaf6f0a6b4231c..e47bad4e33f8f953ea84429a4992d2b2216d9f96 100644 (file)
@@ -75,7 +75,7 @@ static NTSTATUS dcerpc_winreg_Connect(struct dcerpc_binding_handle *b, TALLOC_CT
 }
 
 static bool reg_hive_key(TALLOC_CTX *ctx, const char *fullname,
-                        uint32 *reg_type, const char **key_name)
+                        uint32_t *reg_type, const char **key_name)
 {
        WERROR werr;
        char *hivename = NULL;
@@ -128,11 +128,11 @@ done:
 
 static NTSTATUS registry_openkey(TALLOC_CTX *mem_ctx,
                                 struct rpc_pipe_client *pipe_hnd,
-                                const char *name, uint32 access_mask,
+                                const char *name, uint32_t access_mask,
                                 struct policy_handle *hive_hnd,
                                 struct policy_handle *key_hnd)
 {
-       uint32 hive;
+       uint32_t hive;
        NTSTATUS status;
        WERROR werr;
        struct winreg_String key;
@@ -171,17 +171,17 @@ static NTSTATUS registry_openkey(TALLOC_CTX *mem_ctx,
 static NTSTATUS registry_enumkeys(TALLOC_CTX *ctx,
                                  struct rpc_pipe_client *pipe_hnd,
                                  struct policy_handle *key_hnd,
-                                 uint32 *pnum_keys, char ***pnames,
+                                 uint32_t *pnum_keys, char ***pnames,
                                  char ***pclasses, NTTIME ***pmodtimes)
 {
        TALLOC_CTX *mem_ctx;
        NTSTATUS status;
        WERROR werr;
-       uint32 num_subkeys, max_subkeylen, max_classlen;
-       uint32 num_values, max_valnamelen, max_valbufsize;
-       uint32 i;
+       uint32_t num_subkeys, max_subkeylen, max_classlen;
+       uint32_t num_values, max_valnamelen, max_valbufsize;
+       uint32_t i;
        NTTIME last_changed_time;
-       uint32 secdescsize;
+       uint32_t secdescsize;
        struct winreg_String classname;
        char **names, **classes;
        NTTIME **modtimes;
@@ -293,17 +293,17 @@ static NTSTATUS registry_enumkeys(TALLOC_CTX *ctx,
 static NTSTATUS registry_enumvalues(TALLOC_CTX *ctx,
                                    struct rpc_pipe_client *pipe_hnd,
                                    struct policy_handle *key_hnd,
-                                   uint32 *pnum_values, char ***pvalnames,
+                                   uint32_t *pnum_values, char ***pvalnames,
                                    struct registry_value ***pvalues)
 {
        TALLOC_CTX *mem_ctx;
        NTSTATUS status;
        WERROR werr;
-       uint32 num_subkeys, max_subkeylen, max_classlen;
-       uint32 num_values, max_valnamelen, max_valbufsize;
-       uint32 i;
+       uint32_t num_subkeys, max_subkeylen, max_classlen;
+       uint32_t num_values, max_valnamelen, max_valbufsize;
+       uint32_t i;
        NTTIME last_changed_time;
-       uint32 secdescsize;
+       uint32_t secdescsize;
        struct winreg_String classname;
        struct registry_value **values;
        char **names;
@@ -342,9 +342,9 @@ static NTSTATUS registry_enumvalues(TALLOC_CTX *ctx,
 
        for (i=0; i<num_values; i++) {
                enum winreg_Type type = REG_NONE;
-               uint8 *data = NULL;
-               uint32 data_size;
-               uint32 value_length;
+               uint8_t *data = NULL;
+               uint32_t data_size;
+               uint32_t value_length;
 
                char n;
                struct winreg_ValNameBuf name_buf;
@@ -355,7 +355,7 @@ static NTSTATUS registry_enumvalues(TALLOC_CTX *ctx,
                name_buf.size = max_valnamelen + 2;
 
                data_size = max_valbufsize;
-               data = (uint8 *)TALLOC(mem_ctx, data_size);
+               data = (uint8_t *)TALLOC(mem_ctx, data_size);
                value_length = 0;
 
                status = dcerpc_winreg_EnumValue(b, mem_ctx, key_hnd,
@@ -416,17 +416,17 @@ static NTSTATUS registry_enumvalues(TALLOC_CTX *ctx,
 static NTSTATUS registry_enumvalues2(TALLOC_CTX *ctx,
                                     struct rpc_pipe_client *pipe_hnd,
                                     struct policy_handle *key_hnd,
-                                    uint32 *pnum_values, char ***pvalnames,
+                                    uint32_t *pnum_values, char ***pvalnames,
                                     struct regval_blob ***pvalues)
 {
        TALLOC_CTX *mem_ctx;
        NTSTATUS status;
        WERROR werr;
-       uint32 num_subkeys, max_subkeylen, max_classlen;
-       uint32 num_values, max_valnamelen, max_valbufsize;
-       uint32 i;
+       uint32_t num_subkeys, max_subkeylen, max_classlen;
+       uint32_t num_values, max_valnamelen, max_valbufsize;
+       uint32_t i;
        NTTIME last_changed_time;
-       uint32 secdescsize;
+       uint32_t secdescsize;
        struct winreg_String classname;
        struct regval_blob **values;
        char **names;
@@ -465,9 +465,9 @@ static NTSTATUS registry_enumvalues2(TALLOC_CTX *ctx,
 
        for (i=0; i<num_values; i++) {
                enum winreg_Type type = REG_NONE;
-               uint8 *data = NULL;
-               uint32 data_size;
-               uint32 value_length;
+               uint8_t *data = NULL;
+               uint32_t data_size;
+               uint32_t value_length;
 
                char n;
                struct winreg_ValNameBuf name_buf;
@@ -478,7 +478,7 @@ static NTSTATUS registry_enumvalues2(TALLOC_CTX *ctx,
                name_buf.size = max_valnamelen + 2;
 
                data_size = max_valbufsize;
-               data = (uint8 *)TALLOC(mem_ctx, data_size);
+               data = (uint8_t *)TALLOC(mem_ctx, data_size);
                value_length = 0;
 
                status = dcerpc_winreg_EnumValue(b, mem_ctx, key_hnd,
@@ -603,7 +603,14 @@ static NTSTATUS rpc_registry_setvalue_internal(struct net_context *c,
        }
 
        if (strequal(argv[2], "dword")) {
-               uint32_t v = strtoul(argv[3], NULL, 10);
+               int error = 0;
+               uint32_t v;
+
+               v = smb_strtoul(argv[3], NULL, 10, &error, SMB_STR_STANDARD);
+               if (error != 0) {
+                       goto error;
+               }
+
                value.type = REG_DWORD;
                value.data = data_blob_talloc(mem_ctx, NULL, 4);
                SIVAL(value.data.data, 0, v);
@@ -876,7 +883,7 @@ static NTSTATUS rpc_registry_createkey_internal(struct net_context *c,
                                                int argc,
                                                const char **argv )
 {
-       uint32 hive;
+       uint32_t hive;
        struct policy_handle hive_hnd, key_hnd;
        struct winreg_String key, keyclass;
        enum winreg_CreateAction action;
@@ -962,7 +969,7 @@ static NTSTATUS rpc_registry_deletekey_internal(struct net_context *c,
                                                int argc,
                                                const char **argv )
 {
-       uint32 hive;
+       uint32_t hive;
        struct policy_handle hive_hnd;
        struct winreg_String key;
        NTSTATUS status;
@@ -1034,11 +1041,11 @@ static NTSTATUS rpc_registry_enumerate_internal(struct net_context *c,
        struct policy_handle pol_hive, pol_key;
        NTSTATUS status;
        WERROR werr;
-       uint32 num_subkeys = 0;
-       uint32 num_values = 0;
+       uint32_t num_subkeys = 0;
+       uint32_t num_values = 0;
        char **names = NULL, **classes = NULL;
        NTTIME **modtimes = NULL;
-       uint32 i;
+       uint32_t i;
        struct registry_value **values = NULL;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
@@ -1111,7 +1118,7 @@ static NTSTATUS rpc_registry_save_internal(struct net_context *c,
                                        int argc,
                                        const char **argv )
 {
-       WERROR result = WERR_GENERAL_FAILURE;
+       WERROR result = WERR_GEN_FAILURE;
        struct policy_handle pol_hive, pol_key;
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
        struct winreg_String filename;
@@ -1169,7 +1176,7 @@ static void dump_values( REGF_NK_REC *nk )
 {
        int i, j;
        const char *data_str = NULL;
-       uint32 data_size, data;
+       uint32_t data_size, data;
        DATA_BLOB blob;
 
        if ( !nk->values )
@@ -1183,7 +1190,10 @@ static void dump_values( REGF_NK_REC *nk )
                switch ( nk->values[i].type ) {
                        case REG_SZ:
                                blob = data_blob_const(nk->values[i].data, data_size);
-                               pull_reg_sz(talloc_tos(), &blob, &data_str);
+                               if (!pull_reg_sz(talloc_tos(), &blob,
+                                                &data_str)) {
+                                       data_str = NULL;
+                               }
                                if (!data_str) {
                                        break;
                                }
@@ -1525,12 +1535,12 @@ static NTSTATUS registry_export(struct rpc_pipe_client* pipe_hnd,
                                const char* name)
 {
        NTSTATUS status;
-       uint32 num_subkeys = 0;
-       uint32 num_values = 0;
+       uint32_t num_subkeys = 0;
+       uint32_t num_values = 0;
        char **names = NULL, **classes = NULL;
        NTTIME **modtimes = NULL;
        struct regval_blob **values = NULL;
-       uint32 i;
+       uint32_t i;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
        TALLOC_CTX* mem_ctx = talloc_new(ctx);
@@ -1694,7 +1704,7 @@ static WERROR import_create_key(struct import_ctx* ctx,
        keyname.name = name;
 
        if (parent == NULL) {
-               uint32 hive_idx = 0;
+               uint32_t hive_idx = 0;
                if (!reg_hive_key(mem_ctx, name, &hive_idx, &keyname.name)) {
                        werr = WERR_FOOBAR;
                        goto done;
@@ -1720,7 +1730,7 @@ static WERROR import_create_key(struct import_ctx* ctx,
 
        key = talloc_zero(mem_ctx, struct policy_handle);
        if (key == NULL) {
-               werr = WERR_NOMEM;
+               werr = WERR_NOT_ENOUGH_MEMORY;
                goto done;
        }
 
@@ -1792,7 +1802,7 @@ static WERROR import_delete_key(struct import_ctx* ctx,
        keyname.name = name;
 
        if (parent == NULL) {
-               uint32 hive_idx;
+               uint32_t hive_idx;
                if (!reg_hive_key(mem_ctx, name, &hive_idx, &keyname.name)) {
                        werr = WERR_FOOBAR;
                        goto done;
@@ -1861,7 +1871,7 @@ static WERROR import_close_key(struct import_ctx* ctx,
                goto done;
        }
 
-       werr = (talloc_free(key) == 0) ? WERR_OK : WERR_GENERAL_FAILURE;
+       werr = (talloc_free(key) == 0) ? WERR_OK : WERR_GEN_FAILURE;
 done:
        talloc_free(mem_ctx);
        return werr;
@@ -1878,7 +1888,7 @@ static WERROR import_create_val(struct import_ctx* ctx,
        struct dcerpc_binding_handle *b = ctx->pipe_hnd->binding_handle;
 
        if (parent == NULL) {
-               return WERR_INVALID_PARAM;
+               return WERR_INVALID_PARAMETER;
        }
 
        ZERO_STRUCT(valuename);
@@ -1914,7 +1924,7 @@ static WERROR import_delete_val(struct import_ctx* ctx,
        struct dcerpc_binding_handle *b = ctx->pipe_hnd->binding_handle;
 
        if (parent == NULL) {
-               return WERR_INVALID_PARAM;
+               return WERR_INVALID_PARAMETER;
        }
 
        ZERO_STRUCT(valuename);
@@ -2091,7 +2101,7 @@ int net_rpc_registry(struct net_context *c, int argc, const char **argv)
                        NET_TRANSPORT_RPC,
                        N_("Get security descriptor"),
                        N_("net rpc registry getsd\n"
-                          "    Get security descriptior")
+                          "    Get security descriptor")
                },
                {
                        "import",