s3:netlookup: make use of cli_credentials_init_anon()
[bbaumbach/samba-autobuild/.git] / source3 / utils / net_rpc_sh_acct.c
index 9b788a47156c459650f7ca32d0a10338557f93dd..3fc6568dac6efb2c54e9ffa73dffec5808ce1977 100644 (file)
@@ -18,6 +18,9 @@
 */
 #include "includes.h"
 #include "utils/net.h"
+#include "rpc_client/rpc_client.h"
+#include "../librpc/gen_ndr/ndr_samr_c.h"
+#include "../libcli/security/security.h"
 
 /*
  * Do something with the account policies. Read them all, run a function on
@@ -39,64 +42,87 @@ static NTSTATUS rpc_sh_acct_do(struct net_context *c,
                                          int argc, const char **argv))
 {
        struct policy_handle connect_pol, domain_pol;
-       NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+       NTSTATUS status, result;
        union samr_DomainInfo *info1 = NULL;
        union samr_DomainInfo *info3 = NULL;
        union samr_DomainInfo *info12 = NULL;
        int store;
+       struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
        ZERO_STRUCT(connect_pol);
        ZERO_STRUCT(domain_pol);
 
        /* Get sam policy handle */
 
-       result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
+       status = dcerpc_samr_Connect2(b, mem_ctx,
                                      pipe_hnd->desthost,
                                      MAXIMUM_ALLOWED_ACCESS,
-                                     &connect_pol);
+                                     &connect_pol,
+                                     &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
        if (!NT_STATUS_IS_OK(result)) {
+               status = result;
                goto done;
        }
 
        /* Get domain policy handle */
 
-       result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
+       status = dcerpc_samr_OpenDomain(b, mem_ctx,
                                        &connect_pol,
                                        MAXIMUM_ALLOWED_ACCESS,
                                        ctx->domain_sid,
-                                       &domain_pol);
+                                       &domain_pol,
+                                       &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
        if (!NT_STATUS_IS_OK(result)) {
+               status = result;
                goto done;
        }
 
-       result = rpccli_samr_QueryDomainInfo(pipe_hnd, mem_ctx,
+       status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
                                             &domain_pol,
                                             1,
-                                            &info1);
-
+                                            &info1,
+                                            &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
        if (!NT_STATUS_IS_OK(result)) {
+               status = result;
                d_fprintf(stderr, _("query_domain_info level 1 failed: %s\n"),
                          nt_errstr(result));
                goto done;
        }
 
-       result = rpccli_samr_QueryDomainInfo(pipe_hnd, mem_ctx,
+       status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
                                             &domain_pol,
                                             3,
-                                            &info3);
-
+                                            &info3,
+                                            &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
        if (!NT_STATUS_IS_OK(result)) {
+               status = result;
                d_fprintf(stderr, _("query_domain_info level 3 failed: %s\n"),
                          nt_errstr(result));
                goto done;
        }
 
-       result = rpccli_samr_QueryDomainInfo(pipe_hnd, mem_ctx,
+       status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
                                             &domain_pol,
                                             12,
-                                            &info12);
-
+                                            &info12,
+                                            &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
        if (!NT_STATUS_IS_OK(result)) {
+               status = result;
                d_fprintf(stderr, _("query_domain_info level 12 failed: %s\n"),
                          nt_errstr(result));
                goto done;
@@ -112,38 +138,47 @@ static NTSTATUS rpc_sh_acct_do(struct net_context *c,
 
        switch (store) {
        case 1:
-               result = rpccli_samr_SetDomainInfo(pipe_hnd, mem_ctx,
+               status = dcerpc_samr_SetDomainInfo(b, mem_ctx,
                                                   &domain_pol,
                                                   1,
-                                                  info1);
+                                                  info1,
+                                                  &result);
                break;
        case 3:
-               result = rpccli_samr_SetDomainInfo(pipe_hnd, mem_ctx,
+               status = dcerpc_samr_SetDomainInfo(b, mem_ctx,
                                                   &domain_pol,
                                                   3,
-                                                  info3);
+                                                  info3,
+                                                  &result);
                break;
        case 12:
-               result = rpccli_samr_SetDomainInfo(pipe_hnd, mem_ctx,
+               status = dcerpc_samr_SetDomainInfo(b, mem_ctx,
                                                   &domain_pol,
                                                   12,
-                                                  info12);
+                                                  info12,
+                                                  &result);
                break;
        default:
                d_fprintf(stderr, _("Got unexpected info level %d\n"), store);
-               result = NT_STATUS_INTERNAL_ERROR;
+               status = NT_STATUS_INTERNAL_ERROR;
                goto done;
        }
 
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
+
+       status = result;
+
  done:
        if (is_valid_policy_hnd(&domain_pol)) {
-               rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
+               dcerpc_samr_Close(b, mem_ctx, &domain_pol, &result);
        }
        if (is_valid_policy_hnd(&connect_pol)) {
-               rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
+               dcerpc_samr_Close(b, mem_ctx, &connect_pol, &result);
        }
 
-       return result;
+       return status;
 }
 
 static int account_show(struct net_context *c,
@@ -154,7 +189,7 @@ static int account_show(struct net_context *c,
                        int argc, const char **argv)
 {
        if (argc != 0) {
-               d_fprintf(stderr, _("usage: %s\n"), ctx->whoami);
+               d_fprintf(stderr, "%s %s\n", _("Usage:"), ctx->whoami);
                return -1;
        }
 
@@ -225,7 +260,7 @@ static int account_set_badpw(struct net_context *c,
                             int argc, const char **argv)
 {
        if (argc != 1) {
-               d_fprintf(stderr, _("usage: %s <count>\n"), ctx->whoami);
+               d_fprintf(stderr, "%s %s <count>\n", _("Usage:"), ctx->whoami);
                return -1;
        }
 
@@ -255,7 +290,7 @@ static int account_set_lockduration(struct net_context *c,
                                    int argc, const char **argv)
 {
        if (argc != 1) {
-               d_fprintf(stderr, _("usage: %s <count>\n"), ctx->whoami);
+               d_fprintf(stderr, _("Usage: %s <count>\n"), ctx->whoami);
                return -1;
        }
 
@@ -285,7 +320,7 @@ static int account_set_resetduration(struct net_context *c,
                                     int argc, const char **argv)
 {
        if (argc != 1) {
-               d_fprintf(stderr, _("usage: %s <count>\n"), ctx->whoami);
+               d_fprintf(stderr, _("Usage: %s <count>\n"), ctx->whoami);
                return -1;
        }
 
@@ -315,7 +350,7 @@ static int account_set_minpwage(struct net_context *c,
                                int argc, const char **argv)
 {
        if (argc != 1) {
-               d_fprintf(stderr, _("usage: %s <count>\n"), ctx->whoami);
+               d_fprintf(stderr, _("Usage: %s <count>\n"), ctx->whoami);
                return -1;
        }
 
@@ -345,7 +380,7 @@ static int account_set_maxpwage(struct net_context *c,
                                int argc, const char **argv)
 {
        if (argc != 1) {
-               d_fprintf(stderr, _("usage: %s <count>\n"), ctx->whoami);
+               d_fprintf(stderr, _("Usage: %s <count>\n"), ctx->whoami);
                return -1;
        }
 
@@ -375,7 +410,7 @@ static int account_set_minpwlen(struct net_context *c,
                                int argc, const char **argv)
 {
        if (argc != 1) {
-               d_fprintf(stderr, _("usage: %s <count>\n"), ctx->whoami);
+               d_fprintf(stderr, _("Usage: %s <count>\n"), ctx->whoami);
                return -1;
        }
 
@@ -405,7 +440,7 @@ static int account_set_pwhistlen(struct net_context *c,
                                 int argc, const char **argv)
 {
        if (argc != 1) {
-               d_fprintf(stderr, _("usage: %s <count>\n"), ctx->whoami);
+               d_fprintf(stderr, _("Usage: %s <count>\n"), ctx->whoami);
                return -1;
        }
 
@@ -430,31 +465,24 @@ struct rpc_sh_cmd *net_rpc_acct_cmds(struct net_context *c, TALLOC_CTX *mem_ctx,
                                     struct rpc_sh_ctx *ctx)
 {
        static struct rpc_sh_cmd cmds[9] = {
-               { "show", NULL, NDR_SAMR_UUID, NDR_SAMR_VERSION,
-                 rpc_sh_acct_pol_show,
+               { "show", NULL, &ndr_table_samr, rpc_sh_acct_pol_show,
                  N_("Show current account policy settings") },
-               { "badpw", NULL, NDR_SAMR_UUID, NDR_SAMR_VERSION,
-                 rpc_sh_acct_set_badpw,
+               { "badpw", NULL, &ndr_table_samr, rpc_sh_acct_set_badpw,
                  N_("Set bad password count before lockout") },
-               { "lockduration", NULL, NDR_SAMR_UUID, NDR_SAMR_VERSION,
-                 rpc_sh_acct_set_lockduration,
+               { "lockduration", NULL, &ndr_table_samr, rpc_sh_acct_set_lockduration,
                  N_("Set account lockout duration") },
-               { "resetduration", NULL, NDR_SAMR_UUID, NDR_SAMR_VERSION,
+               { "resetduration", NULL, &ndr_table_samr,
                  rpc_sh_acct_set_resetduration,
                  N_("Set bad password count reset duration") },
-               { "minpwage", NULL, NDR_SAMR_UUID, NDR_SAMR_VERSION,
-                 rpc_sh_acct_set_minpwage,
+               { "minpwage", NULL, &ndr_table_samr, rpc_sh_acct_set_minpwage,
                  N_("Set minimum password age") },
-               { "maxpwage", NULL, NDR_SAMR_UUID, NDR_SAMR_VERSION,
-                 rpc_sh_acct_set_maxpwage,
+               { "maxpwage", NULL, &ndr_table_samr, rpc_sh_acct_set_maxpwage,
                  N_("Set maximum password age") },
-               { "minpwlen", NULL, NDR_SAMR_UUID, NDR_SAMR_VERSION,
-                 rpc_sh_acct_set_minpwlen,
+               { "minpwlen", NULL, &ndr_table_samr, rpc_sh_acct_set_minpwlen,
                  N_("Set minimum password length") },
-               { "pwhistlen", NULL, NDR_SAMR_UUID, NDR_SAMR_VERSION,
-                 rpc_sh_acct_set_pwhistlen,
+               { "pwhistlen", NULL, &ndr_table_samr, rpc_sh_acct_set_pwhistlen,
                  N_("Set the password history length") },
-               { NULL, NULL, NULL, 0, NULL, NULL }
+               { NULL, NULL, 0, NULL, NULL }
        };
 
        return cmds;