diff options
Diffstat (limited to 'source4/utils')
-rw-r--r-- | source4/utils/net/net_gpo.c | 152 |
1 files changed, 138 insertions, 14 deletions
diff --git a/source4/utils/net/net_gpo.c b/source4/utils/net/net_gpo.c index 25dfaa315c..fc25c30fe6 100644 --- a/source4/utils/net/net_gpo.c +++ b/source4/utils/net/net_gpo.c @@ -25,14 +25,22 @@ #include "utils/net/net.h" #include "libgpo/gpo.h" -static int net_gpo_list_all(struct net_context *c, int argc, const char **argv) +static int net_gpo_list_all_usage(struct net_context *ctx, int argc, const char **argv) +{ + d_printf("Syntax: net gpo listall [options]\n"); + d_printf("For a list of available options, please type net gpo listall --help\n"); + return 0; +} + +static int net_gpo_list_all(struct net_context *ctx, int argc, const char **argv) { struct gp_context *gp_ctx; struct gp_object **gpo; - unsigned int i; + const char **gpo_flags; + unsigned int i, j; NTSTATUS rv; - rv = gp_init(c, c->lp_ctx, c->credentials, c->event_ctx, &gp_ctx); + rv = gp_init(ctx, ctx->lp_ctx, ctx->credentials, ctx->event_ctx, &gp_ctx); if (!NT_STATUS_IS_OK(rv)) { DEBUG(0, ("Failed to connect to DC's LDAP: %s\n", get_friendly_nt_error_msg(rv))); return 1; @@ -45,41 +53,157 @@ static int net_gpo_list_all(struct net_context *c, int argc, const char **argv) } for (i = 0; gpo[i] != NULL; i++) { + gp_get_gpo_flags(gp_ctx, gpo[i]->flags, &gpo_flags); + d_printf("GPO : %s\n", gpo[i]->name); d_printf("display name : %s\n", gpo[i]->display_name); d_printf("path : %s\n", gpo[i]->file_sys_path); d_printf("dn : %s\n", gpo[i]->dn); d_printf("version : %d\n", gpo[i]->version); - d_printf("flags : %d\n", gpo[i]->flags); + if (gpo_flags[0] == NULL) { + d_printf("flags : NONE\n"); + } else { + d_printf("flags : %s\n", gpo_flags[0]); + for (j = 1; gpo_flags[j] != NULL; j++) { + d_printf(" %s\n", gpo_flags[i]); + } + } d_printf("\n"); + talloc_free(gpo_flags); } talloc_free(gp_ctx); return 0; } +static int net_gpo_get_gpo_usage(struct net_context *ctx, int argc, const char **argv) +{ + d_printf("Syntax: net gpo getgpo <name> [options]\n"); + d_printf("For a list of available options, please type net gpo getgpo --help\n"); + return 0; +} + +static int net_gpo_get_gpo(struct net_context *ctx, int argc, const char **argv) +{ + struct gp_context *gp_ctx; + struct gp_object *gpo; + const char **gpo_flags; + int i; + NTSTATUS rv; + + if (argc != 1) { + return net_gpo_get_gpo_usage(ctx, argc, argv); + } + + + rv = gp_init(ctx, ctx->lp_ctx, ctx->credentials, ctx->event_ctx, &gp_ctx); + if (!NT_STATUS_IS_OK(rv)) { + DEBUG(0, ("Failed to connect to DC's LDAP: %s\n", get_friendly_nt_error_msg(rv))); + return 1; + } + + rv = gp_get_gpo_info(gp_ctx, argv[0], &gpo); + if (!NT_STATUS_IS_OK(rv)) { + DEBUG(0, ("Failed to get GPO: %s\n", get_friendly_nt_error_msg(rv))); + return 1; + } + + gp_get_gpo_flags(gp_ctx, gpo->flags, &gpo_flags); + + d_printf("GPO : %s\n", gpo->name); + d_printf("display name : %s\n", gpo->display_name); + d_printf("path : %s\n", gpo->file_sys_path); + d_printf("dn : %s\n", gpo->dn); + d_printf("version : %d\n", gpo->version); + if (gpo_flags[0] == NULL) { + d_printf("flags : NONE\n"); + } else { + d_printf("flags : %s\n", gpo_flags[0]); + for (i = 1; gpo_flags[i] != NULL; i++) { + d_printf(" %s\n", gpo_flags[i]); + } + } + d_printf("\n"); + + talloc_free(gp_ctx); + return 0; +} + +static int net_gpo_link_get_usage(struct net_context *ctx, int argc, const char **argv) +{ + d_printf("Syntax: net gpo linkget <name> [options]\n"); + d_printf("For a list of available options, please type net gpo get --help\n"); + return 0; +} + +static int net_gpo_link_get(struct net_context *ctx, int argc, const char **argv) +{ + struct gp_context *gp_ctx; + struct gp_link **links; + NTSTATUS rv; + unsigned int i,j; + const char **options; + + if (argc != 1) { + return net_gpo_link_get_usage(ctx, argc, argv); + } + + rv = gp_init(ctx, ctx->lp_ctx, ctx->credentials, ctx->event_ctx, &gp_ctx); + if (!NT_STATUS_IS_OK(rv)) { + DEBUG(0, ("Failed to connect to DC's LDAP: %s\n", get_friendly_nt_error_msg(rv))); + return 1; + } + + rv = gp_get_gplinks(gp_ctx, argv[0], &links); + if (!NT_STATUS_IS_OK(rv)) { + DEBUG(0, ("Failed to get gplinks: %s\n", get_friendly_nt_error_msg(rv))); + return 1; + } + + for (i = 0; links[i] != NULL; i++) { + gp_get_gplink_options(gp_ctx, links[i]->options, &options); + + d_printf("GPO DN : %s\n", links[i]->dn); + if (options[0] == NULL) { + d_printf("Options : NONE\n"); + } else { + d_printf("Options : %s\n", options[0]); + for (j = 1; options[j] != NULL; j++) { + d_printf(" : %s\n", options[j]); + } + } + d_printf("\n"); + + talloc_free(options); + } + + talloc_free(gp_ctx); + + return 0; +} + static const struct net_functable net_gpo_functable[] = { + { "listall", "List all GPO's on a DC\n", net_gpo_list_all, net_gpo_list_all_usage }, + { "getgpo", "List specificied GPO\n", net_gpo_get_gpo, net_gpo_get_gpo_usage }, + { "linkget", "List gPLink of container\n", net_gpo_link_get, net_gpo_link_get_usage }, /* { "apply", "Apply GPO to container\n", net_gpo_apply, net_gpo_usage }, */ -// { "getgpo", "List specificied GPO\n", net_gpo_get_gpo, net_gpo_usage }, // { "linkadd", "Link a GPO to a container\n", net_gpo_link_add, net_gpo_usage }, /* { "linkdelete", "Delete GPO link from a container\n", net_gpo_link_delete, net_gpo_usage }, */ -// { "linkget", "List gPLink of container\n", net_gpo_link_get, net_gpo_usage }, -// { "list", "List all GPO's for machine/user\n", net_gpo_list, net_gpo_usage }, - { "listall", "List all GPO's on a DC\n", net_gpo_list_all, net_gpo_usage }, +// { "list", "List all GPO's for machine/user\n", net_gpo_list, net_gpo_list_usage }, // { "refresh", "List all GPO's for machine/user and download them\n", net_gpo_refresh, net_gpo_refresh_usage }, { NULL, NULL } }; -int net_gpo(struct net_context *ctx, int argc, const char **argv) -{ - return net_run_function(ctx, argc, argv, net_gpo_functable, net_gpo_usage); -} - int net_gpo_usage(struct net_context *ctx, int argc, const char **argv) { d_printf("Syntax: net gpo <command> [options]\n"); - d_printf("For available commands please type net gpo help\n"); + d_printf("For available commands, please type net gpo help\n"); return 0; } + +int net_gpo(struct net_context *ctx, int argc, const char **argv) +{ + return net_run_function(ctx, argc, argv, net_gpo_functable, net_gpo_usage); +} |