From 5e0c89af5a2e8ef39cb4ca921bfea031a8c77da1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 19:13:26 +0200 Subject: netapi: add NetLocalGroupAdd() example. Guenther (This used to be commit ce60450d831ee2f4ab18c3ce09decee548ec4543) --- .../netapi/examples/localgroup/localgroup_add.c | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_add.c (limited to 'source3/lib/netapi/examples/localgroup') diff --git a/source3/lib/netapi/examples/localgroup/localgroup_add.c b/source3/lib/netapi/examples/localgroup/localgroup_add.c new file mode 100644 index 0000000000..7f23c99db1 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_add.c @@ -0,0 +1,106 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupAdd query + * Copyright (C) Guenther Deschner 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + const char *comment = NULL; + struct LOCALGROUP_INFO_0 g0; + struct LOCALGROUP_INFO_1 g1; + uint32_t parm_error = 0; + uint8_t *buf = NULL; + uint32_t level = 0; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_add", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname comment"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + comment = poptGetArg(pc); + } + + /* NetLocalGroupAdd */ + + if (comment) { + level = 1; + g1.lgrpi1_name = groupname; + g1.lgrpi1_comment = comment; + buf = (uint8_t *)&g1; + } else { + level = 0; + g0.lgrpi0_name = groupname; + buf = (uint8_t *)&g0; + } + + status = NetLocalGroupAdd(hostname, + level, + buf, + &parm_error); + if (status != 0) { + printf("NetLocalGroupAdd failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 808c70340e49fcfd90b4d141ca87f0b0935803e5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 19:46:04 +0200 Subject: netapi: add NetLocalGroupDel() example code. Guenther (This used to be commit 6ebd618cc768df142b035362cc648d8bc2c1bc89) --- .../netapi/examples/localgroup/localgroup_del.c | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_del.c (limited to 'source3/lib/netapi/examples/localgroup') diff --git a/source3/lib/netapi/examples/localgroup/localgroup_del.c b/source3/lib/netapi/examples/localgroup/localgroup_del.c new file mode 100644 index 0000000000..a2515dfdcd --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_del.c @@ -0,0 +1,83 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupDel query + * Copyright (C) Guenther Deschner 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_del", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + /* NetLocalGroupDel */ + + status = NetLocalGroupDel(hostname, + groupname); + if (status != 0) { + printf("NetLocalGroupDel failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From bfef3bb3c6f8f5f1e552a19b9e6395a7f4adfe68 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 20:28:31 +0200 Subject: netapi: add NetLocalGroupGetInfo() example code. Guenther (This used to be commit 591003b109d936b62cc80827971c201b3ea79e39) --- .../examples/localgroup/localgroup_getinfo.c | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_getinfo.c (limited to 'source3/lib/netapi/examples/localgroup') diff --git a/source3/lib/netapi/examples/localgroup/localgroup_getinfo.c b/source3/lib/netapi/examples/localgroup/localgroup_getinfo.c new file mode 100644 index 0000000000..cd8fa8c3b3 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_getinfo.c @@ -0,0 +1,112 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupGetInfo query + * Copyright (C) Guenther Deschner 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + uint8_t *buffer = NULL; + uint32_t level = 0; + struct LOCALGROUP_INFO_0 *g0; + struct LOCALGROUP_INFO_1 *g1; + struct LOCALGROUP_INFO_1002 *g1002; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_getinfo", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetLocalGroupGetInfo */ + + status = NetLocalGroupGetInfo(hostname, + groupname, + level, + &buffer); + if (status != 0) { + printf("NetLocalGroupGetInfo failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + switch (level) { + case 0: + g0 = (struct LOCALGROUP_INFO_0 *)buffer; + printf("name: %s\n", g0->lgrpi0_name); + break; + case 1: + g1 = (struct LOCALGROUP_INFO_1 *)buffer; + printf("name: %s\n", g1->lgrpi1_name); + printf("comment: %s\n", g1->lgrpi1_comment); + break; + case 1002: + g1002 = (struct LOCALGROUP_INFO_1002 *)buffer; + printf("comment: %s\n", g1002->lgrpi1002_comment); + break; + } + NetApiBufferFree(buffer); + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 0ae3f8b926e242e521949c0aa853cc0feba76fce Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Jun 2008 22:37:03 +0200 Subject: netapi: add NetLocalGroupSetInfo() example code. Guenther (This used to be commit abd3f701340a31d9c3779cfe37c639f9105dfdb3) --- .../examples/localgroup/localgroup_setinfo.c | 128 +++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_setinfo.c (limited to 'source3/lib/netapi/examples/localgroup') diff --git a/source3/lib/netapi/examples/localgroup/localgroup_setinfo.c b/source3/lib/netapi/examples/localgroup/localgroup_setinfo.c new file mode 100644 index 0000000000..efcec76786 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_setinfo.c @@ -0,0 +1,128 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupSetInfo query + * Copyright (C) Guenther Deschner 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + uint8_t *buffer = NULL; + uint32_t level = 0; + struct LOCALGROUP_INFO_0 g0; + struct LOCALGROUP_INFO_1 g1; + struct LOCALGROUP_INFO_1002 g1002; + const char *newname = NULL; + const char *newcomment = NULL; + uint32_t parm_err = 0; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + { "newname", 0, POPT_ARG_STRING, NULL, 'n', "New Local Group Name", "NEWNAME" }, + { "newcomment", 0, POPT_ARG_STRING, NULL, 'c', "New Local Group Comment", "NETCOMMENT" }, + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_setinfo", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case 'n': + newname = poptGetOptArg(pc); + break; + case 'c': + newcomment = poptGetOptArg(pc); + break; + } + + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + if (newname && !newcomment) { + g0.lgrpi0_name = newname; + buffer = (uint8_t *)&g0; + level = 0; + } else if (newcomment && !newname) { + g1002.lgrpi1002_comment = newcomment; + buffer = (uint8_t *)&g1002; + level = 1002; + } else if (newname && newcomment) { + g1.lgrpi1_name = newname; + g1.lgrpi1_comment = newcomment; + buffer = (uint8_t *)&g1; + level = 1; + } else { + printf("not enough input\n"); + goto out; + } + + /* NetLocalGroupSetInfo */ + + status = NetLocalGroupSetInfo(hostname, + groupname, + level, + buffer, + &parm_err); + if (status != 0) { + printf("NetLocalGroupSetInfo failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 0c9014da442f04cde27b8e1d93f25c81b30043e3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Jul 2008 01:41:30 +0200 Subject: netapi: add NetLocalGroupEnum example code. Guenther (This used to be commit a5a8d03699220e1f237debb84a75cacbbb8899fa) --- .../netapi/examples/localgroup/localgroup_enum.c | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_enum.c (limited to 'source3/lib/netapi/examples/localgroup') diff --git a/source3/lib/netapi/examples/localgroup/localgroup_enum.c b/source3/lib/netapi/examples/localgroup/localgroup_enum.c new file mode 100644 index 0000000000..6fe0cf4173 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_enum.c @@ -0,0 +1,126 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupEnum query + * Copyright (C) Guenther Deschner 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + uint32_t level = 0; + uint8_t *buffer = NULL; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t resume_handle = 0; + int i; + + struct LOCALGROUP_INFO_0 *info0 = NULL; + struct LOCALGROUP_INFO_1 *info1 = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_enum", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetLocalGroupEnum */ + + do { + status = NetLocalGroupEnum(hostname, + level, + &buffer, + (uint32_t)-1, + &entries_read, + &total_entries, + &resume_handle); + if (status == 0 || status == ERROR_MORE_DATA) { + printf("total entries: %d\n", total_entries); + switch (level) { + case 0: + info0 = (struct LOCALGROUP_INFO_0 *)buffer; + break; + case 1: + info1 = (struct LOCALGROUP_INFO_1 *)buffer; + break; + default: + break; + } + for (i=0; ilgrpi0_name); + info0++; + break; + case 1: + printf("#%d group: %s\n", i, info1->lgrpi1_name); + printf("#%d comment: %s\n", i, info1->lgrpi1_comment); + info1++; + break; + default: + break; + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status != 0) { + printf("NetLocalGroupEnum failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From 6f28bc691a9cf4a79352904cc91c77b17263d7e7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 1 Aug 2008 16:03:00 +0200 Subject: netapi: add NetLocalGroupAddMembers example code. Guenther (This used to be commit 01c4640b1ca66c3285fd23d447d08db12cf83b42) --- .../examples/localgroup/localgroup_addmembers.c | 141 +++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_addmembers.c (limited to 'source3/lib/netapi/examples/localgroup') diff --git a/source3/lib/netapi/examples/localgroup/localgroup_addmembers.c b/source3/lib/netapi/examples/localgroup/localgroup_addmembers.c new file mode 100644 index 0000000000..aa4a9b59b0 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_addmembers.c @@ -0,0 +1,141 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupAddMembers query + * Copyright (C) Guenther Deschner 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + struct LOCALGROUP_MEMBERS_INFO_0 *g0; + struct LOCALGROUP_MEMBERS_INFO_3 *g3; + uint32_t total_entries = 0; + uint8_t *buffer = NULL; + uint32_t level = 3; + const char **names = NULL; + int i = 0; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_addmembers", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname member1 member2 ..."); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + + names = poptGetArgs(pc); + for (i=0; names[i] != NULL; i++) { + total_entries++; + } + + switch (level) { + case 0: + status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries, + (void **)&g0); + if (status) { + printf("NetApiBufferAllocate failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + for (i=0; i Date: Fri, 1 Aug 2008 17:13:43 +0200 Subject: netapi: add NetLocalGroupDelMembers example code. Guenther (This used to be commit b2a413148e470e059c877f4e54955ab61559edee) --- .../examples/localgroup/localgroup_delmembers.c | 141 +++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_delmembers.c (limited to 'source3/lib/netapi/examples/localgroup') diff --git a/source3/lib/netapi/examples/localgroup/localgroup_delmembers.c b/source3/lib/netapi/examples/localgroup/localgroup_delmembers.c new file mode 100644 index 0000000000..7bd3ec0993 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_delmembers.c @@ -0,0 +1,141 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupDelMembers query + * Copyright (C) Guenther Deschner 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + struct LOCALGROUP_MEMBERS_INFO_0 *g0; + struct LOCALGROUP_MEMBERS_INFO_3 *g3; + uint32_t total_entries = 0; + uint8_t *buffer = NULL; + uint32_t level = 3; + const char **names = NULL; + int i = 0; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_delmembers", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname member1 member2 ..."); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + + names = poptGetArgs(pc); + for (i=0; names[i] != NULL; i++) { + total_entries++; + } + + switch (level) { + case 0: + status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries, + (void **)&g0); + if (status) { + printf("NetApiBufferAllocate failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + for (i=0; i Date: Fri, 1 Aug 2008 19:15:52 +0200 Subject: netapi: add NetLocalGroupSetMembers example code. Guenther (This used to be commit 4fea49ae83510225c51c580a2bea2c664851bb39) --- .../examples/localgroup/localgroup_setmembers.c | 141 +++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_setmembers.c (limited to 'source3/lib/netapi/examples/localgroup') diff --git a/source3/lib/netapi/examples/localgroup/localgroup_setmembers.c b/source3/lib/netapi/examples/localgroup/localgroup_setmembers.c new file mode 100644 index 0000000000..acee5cd9c6 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_setmembers.c @@ -0,0 +1,141 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupSetMembers query + * Copyright (C) Guenther Deschner 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + struct LOCALGROUP_MEMBERS_INFO_0 *g0; + struct LOCALGROUP_MEMBERS_INFO_3 *g3; + uint32_t total_entries = 0; + uint8_t *buffer = NULL; + uint32_t level = 3; + const char **names = NULL; + int i = 0; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_setmembers", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname member1 member2 ..."); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + + names = poptGetArgs(pc); + for (i=0; names[i] != NULL; i++) { + total_entries++; + } + + switch (level) { + case 0: + status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries, + (void **)&g0); + if (status) { + printf("NetApiBufferAllocate failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + goto out; + } + + for (i=0; i Date: Tue, 12 Aug 2008 12:49:19 +0200 Subject: netapi: add NetLocalGroupGetMembers example code. Guenther (cherry picked from commit bded298e022028d6237e25e1c785509bc983be9d) (This used to be commit 93b0907aa43e55d2d4093567212b0c9731917351) --- .../examples/localgroup/localgroup_getmembers.c | 165 +++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 source3/lib/netapi/examples/localgroup/localgroup_getmembers.c (limited to 'source3/lib/netapi/examples/localgroup') diff --git a/source3/lib/netapi/examples/localgroup/localgroup_getmembers.c b/source3/lib/netapi/examples/localgroup/localgroup_getmembers.c new file mode 100644 index 0000000000..0589870d02 --- /dev/null +++ b/source3/lib/netapi/examples/localgroup/localgroup_getmembers.c @@ -0,0 +1,165 @@ +/* + * Unix SMB/CIFS implementation. + * NetLocalGroupGetMembers query + * Copyright (C) Guenther Deschner 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include + +#include "common.h" + +int main(int argc, const char **argv) +{ + NET_API_STATUS status; + struct libnetapi_ctx *ctx = NULL; + const char *hostname = NULL; + const char *groupname = NULL; + uint32_t level = 0; + uint8_t *buffer = NULL; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t resume_handle = 0; + char *sid_str = NULL; + int i; + + struct LOCALGROUP_MEMBERS_INFO_0 *info0 = NULL; + struct LOCALGROUP_MEMBERS_INFO_1 *info1 = NULL; + struct LOCALGROUP_MEMBERS_INFO_2 *info2 = NULL; + struct LOCALGROUP_MEMBERS_INFO_3 *info3 = NULL; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + pc = poptGetContext("localgroup_getmembers", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname groupname level"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + groupname = poptGetArg(pc); + + if (poptPeekArg(pc)) { + level = atoi(poptGetArg(pc)); + } + + /* NetLocalGroupGetMembers */ + + do { + status = NetLocalGroupGetMembers(hostname, + groupname, + level, + &buffer, + (uint32_t)-1, + &entries_read, + &total_entries, + &resume_handle); + if (status == 0 || status == ERROR_MORE_DATA) { + printf("total entries: %d\n", total_entries); + switch (level) { + case 0: + info0 = (struct LOCALGROUP_MEMBERS_INFO_0 *)buffer; + break; + case 1: + info1 = (struct LOCALGROUP_MEMBERS_INFO_1 *)buffer; + break; + case 2: + info2 = (struct LOCALGROUP_MEMBERS_INFO_2 *)buffer; + break; + case 3: + info3 = (struct LOCALGROUP_MEMBERS_INFO_3 *)buffer; + break; + default: + break; + } + for (i=0; ilgrmi0_sid, + &sid_str)) { + printf("#%d member sid: %s\n", i, sid_str); + free(sid_str); + } + info0++; + break; + case 1: + if (ConvertSidToStringSid(info1->lgrmi1_sid, + &sid_str)) { + printf("#%d member sid: %s\n", i, sid_str); + free(sid_str); + } + printf("#%d sid type: %d\n", i, info1->lgrmi1_sidusage); + printf("#%d name: %s\n", i, info1->lgrmi1_name); + info1++; + break; + case 2: + if (ConvertSidToStringSid(info2->lgrmi2_sid, + &sid_str)) { + printf("#%d member sid: %s\n", i, sid_str); + free(sid_str); + } + printf("#%d sid type: %d\n", i, info2->lgrmi2_sidusage); + printf("#%d full name: %s\n", i, info2->lgrmi2_domainandname); + info2++; + break; + case 3: + printf("#%d full name: %s\n", i, info3->lgrmi3_domainandname); + info3++; + break; + default: + break; + } + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status != 0) { + printf("NetLocalGroupGetMembers failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From a828a644d0054117cffca02c29b33bdeb1296982 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 5 Sep 2008 23:21:58 +0200 Subject: netapi: re-arrange a little NetLocalGroupSetMembers example code. Guenther (This used to be commit 84a25e69947c077623165fe4535cddd48aba0a3e) --- .../lib/netapi/examples/localgroup/localgroup_setmembers.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source3/lib/netapi/examples/localgroup') diff --git a/source3/lib/netapi/examples/localgroup/localgroup_setmembers.c b/source3/lib/netapi/examples/localgroup/localgroup_setmembers.c index acee5cd9c6..c35f2bbb81 100644 --- a/source3/lib/netapi/examples/localgroup/localgroup_setmembers.c +++ b/source3/lib/netapi/examples/localgroup/localgroup_setmembers.c @@ -40,6 +40,7 @@ int main(int argc, const char **argv) uint32_t level = 3; const char **names = NULL; int i = 0; + size_t buf_size = 0; poptContext pc; int opt; @@ -85,8 +86,9 @@ int main(int argc, const char **argv) switch (level) { case 0: - status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries, - (void **)&g0); + buf_size = sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries; + + status = NetApiBufferAllocate(buf_size, (void **)&g0); if (status) { printf("NetApiBufferAllocate failed with: %s\n", libnetapi_get_error_string(ctx, status)); @@ -103,8 +105,9 @@ int main(int argc, const char **argv) buffer = (uint8_t *)g0; break; case 3: - status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_3) * total_entries, - (void **)&g3); + buf_size = sizeof(struct LOCALGROUP_MEMBERS_INFO_3) * total_entries; + + status = NetApiBufferAllocate(buf_size, (void **)&g3); if (status) { printf("NetApiBufferAllocate failed with: %s\n", libnetapi_get_error_string(ctx, status)); @@ -133,6 +136,8 @@ int main(int argc, const char **argv) libnetapi_get_error_string(ctx, status)); } + NetApiBufferFree(buffer); + out: libnetapi_free(ctx); poptFreeContext(pc); -- cgit