From d0acdc90385302cdac16a4eac0b503e2d3707108 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sun, 13 Apr 2008 19:15:15 +0200 Subject: libnetapi: add NetQueryDisplayInformation example. Guenther (This used to be commit 5f9332cf1f60bb5a23a16776b95af3a83c5deb40) --- source3/lib/netapi/examples/user/user_dispinfo.c | 98 ++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 source3/lib/netapi/examples/user/user_dispinfo.c (limited to 'source3/lib/netapi/examples/user/user_dispinfo.c') diff --git a/source3/lib/netapi/examples/user/user_dispinfo.c b/source3/lib/netapi/examples/user/user_dispinfo.c new file mode 100644 index 0000000000..9f862505aa --- /dev/null +++ b/source3/lib/netapi/examples/user/user_dispinfo.c @@ -0,0 +1,98 @@ +/* + * Unix SMB/CIFS implementation. + * NetQueryDisplayInformation 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; + void *buffer = NULL; + uint32_t entries_read = 0; + uint32_t idx = 0; + int i; + + struct NET_DISPLAY_USER *user; + + 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("user_dispinfo", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname"); + while((opt = poptGetNextOpt(pc)) != -1) { + } + + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; + } + hostname = poptGetArg(pc); + + /* NetQueryDisplayInformation */ + + do { + status = NetQueryDisplayInformation(hostname, + 1, + idx, + 1000, + (uint32_t)-1, + &entries_read, + &buffer); + if (status == 0 || status == ERROR_MORE_DATA) { + user = (struct NET_DISPLAY_USER *)buffer; + for (i=0; iusri1_name); + user++; + } + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (status != 0) { + printf("NetQueryDisplayInformation failed with: %s\n", + libnetapi_get_error_string(ctx, status)); + } + + out: + libnetapi_free(ctx); + poptFreeContext(pc); + + return status; +} -- cgit From b3152fb26849fa90347b315adbbebf57366c9927 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Wed, 9 Jul 2008 10:39:24 +0200 Subject: netapi: Correctly increase idx when displaying user information (This used to be commit 5fad9de2507b88820149def31faa28e5e45f7b5f) --- source3/lib/netapi/examples/user/user_dispinfo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/lib/netapi/examples/user/user_dispinfo.c') diff --git a/source3/lib/netapi/examples/user/user_dispinfo.c b/source3/lib/netapi/examples/user/user_dispinfo.c index 9f862505aa..c7d3112d71 100644 --- a/source3/lib/netapi/examples/user/user_dispinfo.c +++ b/source3/lib/netapi/examples/user/user_dispinfo.c @@ -78,11 +78,13 @@ int main(int argc, const char **argv) if (status == 0 || status == ERROR_MORE_DATA) { user = (struct NET_DISPLAY_USER *)buffer; for (i=0; iusri1_name); + printf("user %d: %s\n", i + idx,i + user->usri1_name); user++; } NetApiBufferFree(buffer); } + idx += entries_read; } while (status == ERROR_MORE_DATA); if (status != 0) { -- cgit From 730678c73177474ef8614f979661d9f6119a61f4 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Jul 2008 22:46:12 +0200 Subject: netapi: fix vim(?)-typo Michael (This used to be commit 7a7bddd75413dba3c0c43fab68a115cf0445f12b) --- source3/lib/netapi/examples/user/user_dispinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/netapi/examples/user/user_dispinfo.c') diff --git a/source3/lib/netapi/examples/user/user_dispinfo.c b/source3/lib/netapi/examples/user/user_dispinfo.c index c7d3112d71..23024fe9fe 100644 --- a/source3/lib/netapi/examples/user/user_dispinfo.c +++ b/source3/lib/netapi/examples/user/user_dispinfo.c @@ -78,7 +78,7 @@ int main(int argc, const char **argv) if (status == 0 || status == ERROR_MORE_DATA) { user = (struct NET_DISPLAY_USER *)buffer; for (i=0; iusri1_name); user++; } -- cgit