[SCM] Samba Shared Repository - branch v3-2-test updated -
release-3-2-0pre2-726-g7d9f64f
Günther Deschner
gd at samba.org
Wed Apr 9 11:51:46 GMT 2008
The branch, v3-2-test has been updated
via 7d9f64fd8401f8abb938757b4f092e25fd6b154f (commit)
from 6c933d0b3838808aeee7f4b29ee89aab8d203538 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test
- Log -----------------------------------------------------------------
commit 7d9f64fd8401f8abb938757b4f092e25fd6b154f
Author: Günther Deschner <gd at samba.org>
Date: Wed Apr 9 13:50:30 2008 +0200
Add NetUserEnum example.
Guenther
-----------------------------------------------------------------------
Summary of changes:
source/lib/netapi/examples/Makefile.in | 8 +++-
.../examples/{getdc/getdc.c => user/user_enum.c} | 48 +++++++++++++-------
2 files changed, 38 insertions(+), 18 deletions(-)
copy source/lib/netapi/examples/{getdc/getdc.c => user/user_enum.c} (65%)
Changeset truncated at 500 lines:
diff --git a/source/lib/netapi/examples/Makefile.in b/source/lib/netapi/examples/Makefile.in
index c00c505..84a8ecf 100644
--- a/source/lib/netapi/examples/Makefile.in
+++ b/source/lib/netapi/examples/Makefile.in
@@ -23,7 +23,8 @@ PROGS = bin/getdc at EXEEXT@ \
bin/netdomjoin-gui at EXEEXT@ \
bin/getjoinableous at EXEEXT@ \
bin/user_add at EXEEXT@ \
- bin/user_del at EXEEXT@
+ bin/user_del at EXEEXT@ \
+ bin/user_enum at EXEEXT@
all: $(PROGS)
@@ -59,6 +60,7 @@ NETDOMJOIN_GUI_OBJ = netdomjoin-gui/netdomjoin-gui.o
GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o $(CMDLINE_OBJ)
USERADD_OBJ = user/user_add.o $(CMDLINE_OBJ)
USERDEL_OBJ = user/user_del.o $(CMDLINE_OBJ)
+USERENUM_OBJ = user/user_enum.o $(CMDLINE_OBJ)
bin/getdc at EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ)
@echo Linking $@
@@ -88,6 +90,10 @@ bin/user_del at EXEEXT@: $(BINARY_PREREQS) $(USERDEL_OBJ)
@echo Linking $@
@$(CC) $(FLAGS) -o $@ $(USERDEL_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS)
+bin/user_enum at EXEEXT@: $(BINARY_PREREQS) $(USERENUM_OBJ)
+ @echo Linking $@
+ @$(CC) $(FLAGS) -o $@ $(USERENUM_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS)
+
clean:
-rm -f $(PROGS)
-rm -f core */*~ *~ \
diff --git a/source/lib/netapi/examples/getdc/getdc.c b/source/lib/netapi/examples/user/user_enum.c
similarity index 65%
copy from source/lib/netapi/examples/getdc/getdc.c
copy to source/lib/netapi/examples/user/user_enum.c
index 98bb6a1..e1f6bda 100644
--- a/source/lib/netapi/examples/getdc/getdc.c
+++ b/source/lib/netapi/examples/user/user_enum.c
@@ -1,6 +1,6 @@
/*
* Unix SMB/CIFS implementation.
- * GetDCName query
+ * NetUserEnum query
* Copyright (C) Guenther Deschner 2007
*
* This program is free software; you can redistribute it and/or modify
@@ -31,10 +31,14 @@ int main(int argc, const char **argv)
{
NET_API_STATUS status;
struct libnetapi_ctx *ctx = NULL;
-
const char *hostname = NULL;
- const char *domain = NULL;
uint8_t *buffer = NULL;
+ uint32_t entries_read = 0;
+ uint32_t total_entries = 0;
+ uint32_t resume_handle = 0;
+ int i;
+
+ struct USER_INFO_0 *info0;
poptContext pc;
int opt;
@@ -50,9 +54,9 @@ int main(int argc, const char **argv)
return status;
}
- pc = poptGetContext("getdc", argc, argv, long_options, 0);
+ pc = poptGetContext("user_enum", argc, argv, long_options, 0);
- poptSetOtherOptionHelp(pc, "hostname domainname");
+ poptSetOtherOptionHelp(pc, "hostname");
while((opt = poptGetNextOpt(pc)) != -1) {
}
@@ -62,23 +66,33 @@ int main(int argc, const char **argv)
}
hostname = poptGetArg(pc);
- if (!poptPeekArg(pc)) {
- poptPrintHelp(pc, stderr, 0);
- goto out;
- }
- domain = poptGetArg(pc);
-
- /* NetGetDCName */
+ /* NetUserEnum */
+
+ do {
+ status = NetUserEnum(hostname,
+ 0,
+ 0,
+ &buffer,
+ (uint32_t)-1,
+ &entries_read,
+ &total_entries,
+ &resume_handle);
+ if (status == 0 || status == ERROR_MORE_DATA) {
+ info0 = (struct USER_INFO_0 *)buffer;
+ for (i=0; i<entries_read; i++) {
+ printf("user %d: %s\n", i, info0->usri0_name);
+ info0++;
+ }
+ NetApiBufferFree(buffer);
+ }
+ } while (status == ERROR_MORE_DATA);
- status = NetGetDCName(hostname, domain, &buffer);
if (status != 0) {
- printf("GetDcName failed with: %s\n", libnetapi_errstr(status));
- } else {
- printf("%s\n", (char *)buffer);
+ printf("NetUserEnum failed with: %s\n",
+ libnetapi_get_error_string(ctx, status));
}
out:
- NetApiBufferFree(buffer);
libnetapi_free(ctx);
poptFreeContext(pc);
--
Samba Shared Repository
More information about the samba-cvs
mailing list