s3-auth Use the common gensec_ntlmssp_update in gensec_ntlmssp3_server
[ira/wip.git] / source3 / utils / net_ads_gpo.c
index 7484726e7717cbe7821630300ad3035741dc9f8a..56451ab11e1c2332680149f5db5e919c36b1e5fe 100644 (file)
 
 #include "includes.h"
 #include "utils/net.h"
+#include "ads.h"
+#include "../libgpo/gpo.h"
+#include "libgpo/gpo_proto.h"
+#include "../libds/common/flags.h"
 
 #ifdef HAVE_ADS
 
@@ -34,15 +38,16 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
        uint32 flags = 0;
        struct GROUP_POLICY_OBJECT *gpo;
        NTSTATUS result;
-       struct nt_user_token *token = NULL;
+       struct security_token *token = NULL;
 
        if (argc < 1 || c->display_usage) {
-               d_printf("Usage:\n"
-                        "net ads gpo refresh <username|machinename>\n"
-                        "  Lists all GPOs assigned to an account and "
-                        "downloads them\n"
-                        "    username\tUser to refresh GPOs for\n"
-                        "    machinename\tMachine to refresh GPOs for\n");
+               d_printf("%s\n%s\n%s",
+                        _("Usage:"),
+                        _("net ads gpo refresh <username|machinename>"),
+                        _("  Lists all GPOs assigned to an account and "
+                          "downloads them\n"
+                          "    username\tUser to refresh GPOs for\n"
+                          "    machinename\tMachine to refresh GPOs for\n"));
                return -1;
        }
 
@@ -53,13 +58,13 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
 
        status = ads_startup(c, false, &ads);
        if (!ADS_ERR_OK(status)) {
-               d_printf("failed to connect AD server: %s\n", ads_errstr(status));
+               d_printf(_("failed to connect AD server: %s\n"), ads_errstr(status));
                goto out;
        }
 
        status = ads_find_samaccount(ads, mem_ctx, argv[0], &uac, &dn);
        if (!ADS_ERR_OK(status)) {
-               d_printf("failed to find samaccount for %s\n", argv[0]);
+               d_printf(_("failed to find samaccount for %s\n"), argv[0]);
                goto out;
        }
 
@@ -67,11 +72,11 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
                flags |= GPO_LIST_FLAG_MACHINE;
        }
 
-       d_printf("\n%s: '%s' has dn: '%s'\n\n",
-               (uac & UF_WORKSTATION_TRUST_ACCOUNT) ? "machine" : "user",
+       d_printf(_("\n%s: '%s' has dn: '%s'\n\n"),
+               (uac & UF_WORKSTATION_TRUST_ACCOUNT) ? _("machine") : _("user"),
                argv[0], dn);
 
-       d_printf("* fetching token ");
+       d_printf(_("* fetching token "));
        if (uac & UF_WORKSTATION_TRUST_ACCOUNT) {
                status = gp_get_machine_token(ads, mem_ctx, NULL, dn, &token);
        } else {
@@ -79,46 +84,47 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
        }
 
        if (!ADS_ERR_OK(status)) {
-               d_printf("failed: %s\n", ads_errstr(status));
+               d_printf(_("failed: %s\n"), ads_errstr(status));
                goto out;
        }
-       d_printf("finished\n");
+       d_printf(_("finished\n"));
 
-       d_printf("* fetching GPO List ");
+       d_printf(_("* fetching GPO List "));
        status = ads_get_gpo_list(ads, mem_ctx, dn, flags, token, &gpo_list);
        if (!ADS_ERR_OK(status)) {
-               d_printf("failed: %s\n", ads_errstr(status));
+               d_printf(_("failed: %s\n"),
+                        ads_errstr(status));
                goto out;
        }
-       d_printf("finished\n");
+       d_printf(_("finished\n"));
 
-       d_printf("* refreshing Group Policy Data ");
+       d_printf(_("* Refreshing Group Policy Data "));
        if (!NT_STATUS_IS_OK(result = check_refresh_gpo_list(ads, mem_ctx,
                                                             cache_path(GPO_CACHE_DIR),
                                                             NULL,
                                                             flags,
                                                             gpo_list))) {
-               d_printf("failed: %s\n", nt_errstr(result));
+               d_printf(_("failed: %s\n"), nt_errstr(result));
                goto out;
        }
-       d_printf("finished\n");
+       d_printf(_("finished\n"));
 
-       d_printf("* storing GPO list to registry ");
+       d_printf(_("* storing GPO list to registry "));
 
        {
                WERROR werr = gp_reg_state_store(mem_ctx, flags, dn,
                                                 token, gpo_list);
                if (!W_ERROR_IS_OK(werr)) {
-                       d_printf("failed: %s\n", win_errstr(werr));
+                       d_printf(_("failed: %s\n"), win_errstr(werr));
                        goto out;
                }
        }
 
-       d_printf("finished\n");
+       d_printf(_("finished\n"));
 
        if (c->opt_verbose) {
 
-               d_printf("* dumping GPO list\n");
+               d_printf(_("* dumping GPO list\n"));
 
                for (gpo = gpo_list; gpo; gpo = gpo->next) {
 
@@ -147,23 +153,23 @@ static int net_ads_gpo_refresh(struct net_context *c, int argc, const char **arg
                }
        }
 
-       d_printf("* re-reading GPO list from registry ");
+       d_printf(_("* re-reading GPO list from registry "));
 
        {
                WERROR werr = gp_reg_state_read(mem_ctx, flags,
-                                               &token->user_sids[0],
+                                               &token->sids[0],
                                                &read_list);
                if (!W_ERROR_IS_OK(werr)) {
-                       d_printf("failed: %s\n", win_errstr(werr));
+                       d_printf(_("failed: %s\n"), win_errstr(werr));
                        goto out;
                }
        }
 
-       d_printf("finished\n");
+       d_printf(_("finished\n"));
 
        if (c->opt_verbose) {
 
-               d_printf("* dumping GPO list from registry\n");
+               d_printf(_("* dumping GPO list from registry\n"));
 
                for (gpo = read_list; gpo; gpo = gpo->next) {
 
@@ -222,9 +228,11 @@ static int net_ads_gpo_list_all(struct net_context *c, int argc, const char **ar
        };
 
        if (c->display_usage) {
-               d_printf("Usage:\n"
-                        "net ads gpo listall\n"
-                        "    List all GPOs on the DC\n");
+               d_printf(  "%s\n"
+                          "net ads gpo listall\n"
+                          "    %s\n",
+                        _("Usage:"),
+                        _("List all GPOs on the DC"));
                return 0;
        }
 
@@ -242,17 +250,17 @@ static int net_ads_gpo_list_all(struct net_context *c, int argc, const char **ar
                                            LDAP_SCOPE_SUBTREE,
                                            "(objectclass=groupPolicyContainer)",
                                            attrs,
-                                           DACL_SECURITY_INFORMATION,
+                                           SECINFO_DACL,
                                            &res);
 
        if (!ADS_ERR_OK(status)) {
-               d_printf("search failed: %s\n", ads_errstr(status));
+               d_printf(_("search failed: %s\n"), ads_errstr(status));
                goto out;
        }
 
        num_reply = ads_count_replies(ads, res);
 
-       d_printf("Got %d replies\n\n", num_reply);
+       d_printf(_("Got %d replies\n\n"), num_reply);
 
        /* dump the results */
        for (msg = ads_first_entry(ads, res);
@@ -266,7 +274,7 @@ static int net_ads_gpo_list_all(struct net_context *c, int argc, const char **ar
                status = ads_parse_gpo(ads, mem_ctx, msg, dn, &gpo);
 
                if (!ADS_ERR_OK(status)) {
-                       d_printf("ads_parse_gpo failed: %s\n",
+                       d_printf(_("ads_parse_gpo failed: %s\n"),
                                ads_errstr(status));
                        goto out;
                }
@@ -285,7 +293,7 @@ out:
 
 static int net_ads_gpo_list(struct net_context *c, int argc, const char **argv)
 {
-       ADS_STRUCT *ads;
+       ADS_STRUCT *ads = NULL;
        ADS_STATUS status;
        LDAPMessage *res = NULL;
        TALLOC_CTX *mem_ctx;
@@ -293,14 +301,15 @@ static int net_ads_gpo_list(struct net_context *c, int argc, const char **argv)
        uint32 uac = 0;
        uint32 flags = 0;
        struct GROUP_POLICY_OBJECT *gpo_list;
-       struct nt_user_token *token = NULL;
+       struct security_token *token = NULL;
 
        if (argc < 1 || c->display_usage) {
-               d_printf("Usage:\n"
-                        "net ads gpo list <username|machinename>\n"
-                        "  Lists all GPOs for machine/user\n"
-                        "    username\tUser to list GPOs for\n"
-                        "    machinename\tMachine to list GPOs for\n");
+               d_printf("%s\n%s\n%s",
+                        _("Usage:"),
+                        _("net ads gpo list <username|machinename>"),
+                        _("  Lists all GPOs for machine/user\n"
+                          "    username\tUser to list GPOs for\n"
+                          "    machinename\tMachine to list GPOs for\n"));
                return -1;
        }
 
@@ -323,8 +332,8 @@ static int net_ads_gpo_list(struct net_context *c, int argc, const char **argv)
                flags |= GPO_LIST_FLAG_MACHINE;
        }
 
-       d_printf("%s: '%s' has dn: '%s'\n",
-               (uac & UF_WORKSTATION_TRUST_ACCOUNT) ? "machine" : "user",
+       d_printf(_("%s: '%s' has dn: '%s'\n"),
+               (uac & UF_WORKSTATION_TRUST_ACCOUNT) ? _("machine") : _("user"),
                argv[0], dn);
 
        if (uac & UF_WORKSTATION_TRUST_ACCOUNT) {
@@ -353,7 +362,6 @@ out:
        return 0;
 }
 
-#if 0
 static int net_ads_gpo_apply(struct net_context *c, int argc, const char **argv)
 {
        TALLOC_CTX *mem_ctx;
@@ -363,7 +371,7 @@ static int net_ads_gpo_apply(struct net_context *c, int argc, const char **argv)
        struct GROUP_POLICY_OBJECT *gpo_list;
        uint32 uac = 0;
        uint32 flags = 0;
-       struct nt_user_token *token = NULL;
+       struct security_token *token = NULL;
        const char *filter = NULL;
 
        if (argc < 1 || c->display_usage) {
@@ -385,6 +393,8 @@ static int net_ads_gpo_apply(struct net_context *c, int argc, const char **argv)
        }
 
        status = ads_startup(c, false, &ads);
+       /* filter = cse_gpo_name_to_guid_string("Security"); */
+
        if (!ADS_ERR_OK(status)) {
                d_printf("got: %s\n", ads_errstr(status));
                goto out;
@@ -437,7 +447,6 @@ out:
        talloc_destroy(mem_ctx);
        return 0;
 }
-#endif
 
 static int net_ads_gpo_link_get(struct net_context *c, int argc, const char **argv)
 {
@@ -447,10 +456,11 @@ static int net_ads_gpo_link_get(struct net_context *c, int argc, const char **ar
        struct GP_LINK gp_link;
 
        if (argc < 1 || c->display_usage) {
-               d_printf("Usage:\n"
-                        "net ads gpo linkget <container>\n"
-                        "  Lists gPLink of a containter\n"
-                        "    container\tContainer to get link for\n");
+               d_printf("%s\n%s\n%s",
+                        _("Usage:"),
+                        _("net ads gpo linkget <container>"),
+                        _("  Lists gPLink of a containter\n"
+                          "    container\tContainer to get link for\n"));
                return -1;
        }
 
@@ -466,7 +476,7 @@ static int net_ads_gpo_link_get(struct net_context *c, int argc, const char **ar
 
        status = ads_get_gpo_link(ads, mem_ctx, argv[0], &gp_link);
        if (!ADS_ERR_OK(status)) {
-               d_printf("get link for %s failed: %s\n", argv[0],
+               d_printf(_("get link for %s failed: %s\n"), argv[0],
                        ads_errstr(status));
                goto out;
        }
@@ -488,13 +498,14 @@ static int net_ads_gpo_link_add(struct net_context *c, int argc, const char **ar
        TALLOC_CTX *mem_ctx;
 
        if (argc < 2 || c->display_usage) {
-               d_printf("Usage:\n"
-                        "net ads gpo linkadd <linkdn> <gpodn> [options]\n"
-                        "  Link a container to a GPO\n"
-                        "    linkdn\tContainer to link to a GPO\n"
-                        "    gpodn\tGPO to link container to\n");
-               d_printf("note: DNs must be provided properly escaped.\n");
-               d_printf("See RFC 4514 for details\n");
+               d_printf("%s\n%s\n%s",
+                        _("Usage:"),
+                        _("net ads gpo linkadd <linkdn> <gpodn> [options]"),
+                        _("  Link a container to a GPO\n"
+                          "    linkdn\tContainer to link to a GPO\n"
+                          "    gpodn\tGPO to link container to\n"));
+               d_printf(_("note: DNs must be provided properly escaped.\n"
+                          "See RFC 4514 for details\n"));
                return -1;
        }
 
@@ -514,7 +525,7 @@ static int net_ads_gpo_link_add(struct net_context *c, int argc, const char **ar
 
        status = ads_add_gpo_link(ads, mem_ctx, argv[0], argv[1], gpo_opt);
        if (!ADS_ERR_OK(status)) {
-               d_printf("link add failed: %s\n", ads_errstr(status));
+               d_printf(_("link add failed: %s\n"), ads_errstr(status));
                goto out;
        }
 
@@ -575,10 +586,11 @@ static int net_ads_gpo_get_gpo(struct net_context *c, int argc, const char **arg
        struct GROUP_POLICY_OBJECT gpo;
 
        if (argc < 1 || c->display_usage) {
-               d_printf("Usage:\n"
-                        "net ads gpo getgpo <gpo>\n"
-                        "  List speciefied GPO\n"
-                        "    gpo\t\tGPO to list\n");
+               d_printf("%s\n%s\n%s",
+                        _("Usage:"),
+                        _("net ads gpo getgpo <gpo>"),
+                        _("  List speciefied GPO\n"
+                          "    gpo\t\tGPO to list\n"));
                return -1;
        }
 
@@ -599,7 +611,7 @@ static int net_ads_gpo_get_gpo(struct net_context *c, int argc, const char **arg
        }
 
        if (!ADS_ERR_OK(status)) {
-               d_printf("get gpo for [%s] failed: %s\n", argv[0],
+               d_printf(_("get gpo for [%s] failed: %s\n"), argv[0],
                        ads_errstr(status));
                goto out;
        }
@@ -616,7 +628,6 @@ out:
 int net_ads_gpo(struct net_context *c, int argc, const char **argv)
 {
        struct functable func[] = {
-#if 0
                {
                        "apply",
                        net_ads_gpo_apply,
@@ -625,22 +636,21 @@ int net_ads_gpo(struct net_context *c, int argc, const char **argv)
                        "net ads gpo apply\n"
                        "    Apply GPO to container"
                },
-#endif
                {
                        "getgpo",
                        net_ads_gpo_get_gpo,
                        NET_TRANSPORT_ADS,
-                       "List specified GPO",
-                       "net ads gpo getgpo\n"
-                       "    List specified GPO"
+                       N_("List specified GPO"),
+                       N_("net ads gpo getgpo\n"
+                          "    List specified GPO")
                },
                {
                        "linkadd",
                        net_ads_gpo_link_add,
                        NET_TRANSPORT_ADS,
-                       "Link a container to a GPO",
-                       "net ads gpo linkadd\n"
-                       "    Link a container to a GPO"
+                       N_("Link a container to a GPO"),
+                       N_("net ads gpo linkadd\n"
+                          "    Link a container to a GPO")
                },
 #if 0
                {
@@ -656,35 +666,35 @@ int net_ads_gpo(struct net_context *c, int argc, const char **argv)
                        "linkget",
                        net_ads_gpo_link_get,
                        NET_TRANSPORT_ADS,
-                       "Lists gPLink of containter",
-                       "net ads gpo linkget\n"
-                       "    Lists gPLink of containter"
+                       N_("Lists gPLink of containter"),
+                       N_("net ads gpo linkget\n"
+                          "    Lists gPLink of containter")
                },
                {
                        "list",
                        net_ads_gpo_list,
                        NET_TRANSPORT_ADS,
-                       "Lists all GPOs for machine/user",
-                       "net ads gpo list\n"
-                       "    Lists all GPOs for machine/user"
+                       N_("Lists all GPOs for machine/user"),
+                       N_("net ads gpo list\n"
+                          "    Lists all GPOs for machine/user")
                },
                {
                        "listall",
                        net_ads_gpo_list_all,
                        NET_TRANSPORT_ADS,
-                       "Lists all GPOs on a DC",
-                       "net ads gpo listall\n"
-                       "    Lists all GPOs on a DC"
+                       N_("Lists all GPOs on a DC"),
+                       N_("net ads gpo listall\n"
+                          "    Lists all GPOs on a DC")
                },
                {
                        "refresh",
                        net_ads_gpo_refresh,
                        NET_TRANSPORT_ADS,
-                       "Lists all GPOs assigned to an account and downloads "
-                       "them",
-                       "net ads gpo refresh\n"
-                       "    Lists all GPOs assigned to an account and "
-                       "downloads them"
+                       N_("Lists all GPOs assigned to an account and "
+                          "downloads them"),
+                       N_("net ads gpo refresh\n"
+                          "    Lists all GPOs assigned to an account and "
+                          "downloads them")
                },
                {NULL, NULL, 0, NULL, NULL}
        };