[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-test-1497-g8858e40

Günther Deschner gd at samba.org
Fri Jan 18 01:56:55 GMT 2008


The branch, v3-2-test has been updated
       via  8858e403e1940c362d307b4d4125f977abb0b96a (commit)
       via  4ca33928512bd71268bafd41d2b608e814a7295f (commit)
       via  d4c5b323229c6f43c824e3559084c98e370730a5 (commit)
       via  30458116b389889cad845eb96b54c3edc833e722 (commit)
       via  96f645553ae5c75aabfe588e1a67f3d4bfacb5cb (commit)
      from  7aec862ddc2aa2b5152c3a452971e55ba43646a5 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit 8858e403e1940c362d307b4d4125f977abb0b96a
Author: Günther Deschner <gd at samba.org>
Date:   Fri Jan 18 02:50:33 2008 +0100

    Add NetGetJoinableOUs() to libnetapi (incl. example).
    
    Guenther

commit 4ca33928512bd71268bafd41d2b608e814a7295f
Author: Günther Deschner <gd at samba.org>
Date:   Fri Jan 18 02:38:35 2008 +0100

    Cosmetics and error string reporting for libnetapi.
    
    Guenther

commit d4c5b323229c6f43c824e3559084c98e370730a5
Author: Günther Deschner <gd at samba.org>
Date:   Fri Jan 18 02:30:53 2008 +0100

    Add some more debugging into netdomjoin-gui.
    
    Guenther

commit 30458116b389889cad845eb96b54c3edc833e722
Author: Günther Deschner <gd at samba.org>
Date:   Fri Jan 18 02:30:09 2008 +0100

    Fix local hostname detection in netdomjoin-gui.
    
    Guenther

commit 96f645553ae5c75aabfe588e1a67f3d4bfacb5cb
Author: Günther Deschner <gd at samba.org>
Date:   Fri Jan 18 01:56:01 2008 +0100

    Improve libnetapi_set_error_string().
    
    Guenther

-----------------------------------------------------------------------

Summary of changes:
 source/lib/netapi/examples/Makefile.in             |   16 +-
 .../getjoinableous.c}                              |   68 ++----
 .../examples/netdomjoin-gui/netdomjoin-gui.c       |   50 +++-
 source/lib/netapi/getdc.c                          |   30 +++-
 source/lib/netapi/joindomain.c                     |  249 +++++++++++++++++++-
 source/lib/netapi/netapi.c                         |   11 +-
 source/lib/netapi/netapi.h                         |   35 +++-
 source/lib/netapi/serverinfo.c                     |   43 +++-
 8 files changed, 420 insertions(+), 82 deletions(-)
 copy source/lib/netapi/examples/{netdomjoin/netdomjoin.c => getjoinableous/getjoinableous.c} (55%)


Changeset truncated at 500 lines:

diff --git a/source/lib/netapi/examples/Makefile.in b/source/lib/netapi/examples/Makefile.in
index c2f453d..86e1b1b 100644
--- a/source/lib/netapi/examples/Makefile.in
+++ b/source/lib/netapi/examples/Makefile.in
@@ -5,7 +5,7 @@ KRB5LIBS=@KRB5_LIBS@
 LDAP_LIBS=@LDAP_LIBS@
 LIBS=@LIBS@ -lnetapi
 DEVELOPER_CFLAGS=@DEVELOPER_CFLAGS@
-FLAGS=@CFLAGS@ $(GTK_FLAGS)
+FLAGS=-I../ -L../../../bin @CFLAGS@ $(GTK_FLAGS)
 CC=@CC@
 LDFLAGS=@PIE_LDFLAGS@ @LDFLAGS@
 DYNEXP=@DYNEXP@
@@ -36,8 +36,12 @@ MAKEDIR = || exec false; \
 GETDC_OBJ = getdc/getdc.o
 NETDOMJOIN_OBJ = netdomjoin/netdomjoin.o
 NETDOMJOIN_GUI_OBJ = netdomjoin-gui/netdomjoin-gui.o
+GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o
 
-PROGS = bin/getdc at EXEEXT@ bin/netdomjoin at EXEEXT@ bin/netdomjoin-gui at EXEEXT@
+PROGS = bin/getdc at EXEEXT@ \
+	bin/netdomjoin at EXEEXT@ \
+	bin/netdomjoin-gui at EXEEXT@ \
+	bin/getjoinableous at EXEEXT@
 
 all: $(PROGS)
 
@@ -45,6 +49,10 @@ bin/getdc at EXEEXT@: $(GETDC_OBJ)
 	@echo Linking $@
 	@$(CC) $(FLAGS) -o $@ $(GETDC_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS)
 
+bin/getjoinableous at EXEEXT@: $(GETJOINABLEOUS_OBJ)
+	@echo Linking $@
+	@$(CC) $(FLAGS) -o $@ $(GETJOINABLEOUS_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS)
+
 bin/netdomjoin at EXEEXT@: $(NETDOMJOIN_OBJ)
 	@echo Linking $@
 	@$(CC) $(FLAGS) -o $@ $(NETDOMJOIN_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS)
@@ -54,4 +62,6 @@ bin/netdomjoin-gui at EXEEXT@: $(NETDOMJOIN_GUI_OBJ)
 	@$(CC) $(FLAGS) $(GTK_FLAGS) -o $@ $(NETDOMJOIN_GUI_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) $(GTK_LIBS)
 
 clean:
-	@rm -f $(PROGS)
+	-rm -f $(PROGS)
+	-rm -f core */*~ *~ \
+		*/*.o */*/*.o */*/*/*.o \
diff --git a/source/lib/netapi/examples/netdomjoin/netdomjoin.c b/source/lib/netapi/examples/getjoinableous/getjoinableous.c
similarity index 55%
copy from source/lib/netapi/examples/netdomjoin/netdomjoin.c
copy to source/lib/netapi/examples/getjoinableous/getjoinableous.c
index 29f66a1..5a3366c 100644
--- a/source/lib/netapi/examples/netdomjoin/netdomjoin.c
+++ b/source/lib/netapi/examples/getjoinableous/getjoinableous.c
@@ -1,7 +1,7 @@
 /*
  *  Unix SMB/CIFS implementation.
  *  Join Support (cmdline + netapi)
- *  Copyright (C) Guenther Deschner 2007-2008
+ *  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
@@ -17,11 +17,8 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <sys/types.h>
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
+#include <stdio.h>
 
 #include <netapi.h>
 
@@ -42,10 +39,10 @@ int main(int argc, char **argv)
 	NET_API_STATUS status;
 	const char *server_name = NULL;
 	const char *domain_name = NULL;
-	const char *account_ou = NULL;
-	const char *Account = NULL;
+	const char *account = NULL;
 	const char *password = NULL;
-	uint32_t join_flags = 3;
+	const char **ous = NULL;
+	uint32_t num_ous = 0;
 	struct libnetapi_ctx *ctx = NULL;
 	int i;
 
@@ -55,11 +52,8 @@ int main(int argc, char **argv)
 	}
 
 	if (argc < 2) {
-		printf("usage: netdomjoin\n");
-		printf("\t[hostname] [domain=DOMAIN] <ou=OU> "
-		       "<usero=USERO> <passwordo=PASSWORDO> "
-		       "<userd=USERD> <passwordd=PASSWORDD> "
-		       "<debug=DEBUGLEVEL>\n");
+		printf("usage: getjoinableous\n");
+		printf("\t<hostname> [domain=DOMAIN] <user=USER> <password=PASSWORD>\n");
 		return 0;
 	}
 
@@ -68,27 +62,16 @@ int main(int argc, char **argv)
 	}
 
 	for (i=0; i<argc; i++) {
-		if (strncasecmp(argv[i], "ou", strlen("ou")) == 0) {
-			account_ou = get_string_param(argv[i]);
-		}
 		if (strncasecmp(argv[i], "domain", strlen("domain"))== 0) {
 			domain_name = get_string_param(argv[i]);
 		}
-		if (strncasecmp(argv[i], "userd", strlen("userd"))== 0) {
-			Account = get_string_param(argv[i]);
+		if (strncasecmp(argv[i], "user", strlen("user"))== 0) {
+			account = get_string_param(argv[i]);
+			libnetapi_set_username(ctx, account);
 		}
-		if (strncasecmp(argv[i], "passwordd", strlen("passwordd"))== 0) {
+		if (strncasecmp(argv[i], "password", strlen("password"))== 0) {
 			password = get_string_param(argv[i]);
-		}
-		if (strncasecmp(argv[i], "usero", strlen("usero"))== 0) {
-			const char *str = NULL;
-			str = get_string_param(argv[i]);
-			libnetapi_set_username(ctx, str);
-		}
-		if (strncasecmp(argv[i], "passwordo", strlen("passwordo"))== 0) {
-			const char *str = NULL;
-			str = get_string_param(argv[i]);
-			libnetapi_set_password(ctx, str);
+			libnetapi_set_password(ctx, password);
 		}
 		if (strncasecmp(argv[i], "debug", strlen("debug"))== 0) {
 			const char *str = NULL;
@@ -97,23 +80,24 @@ int main(int argc, char **argv)
 		}
 	}
 
-	status = NetJoinDomain(server_name,
-			       domain_name,
-			       account_ou,
-			       Account,
-			       password,
-			       join_flags);
+	status = NetGetJoinableOUs(server_name,
+				   domain_name,
+				   account,
+				   password,
+				   &num_ous,
+				   &ous);
 	if (status != 0) {
-		const char *errstr = NULL;
-		errstr = libnetapi_get_error_string(ctx, status);
-		if (!errstr) {
-			errstr = libnetapi_errstr(status);
-		}
-		printf("Join failed with: %s\n", errstr);
+		printf("failed with: %s\n",
+			libnetapi_get_error_string(ctx, status));
 	} else {
-		printf("Successfully joined\n");
+		printf("Successfully queried joinable ous:\n");
+		for (i=0; i<num_ous; i++) {
+			printf("ou: %s\n", ous[i]);
+		}
 	}
 
+	NetApiBufferFree(ous);
+
 	libnetapi_free(ctx);
 
 	return status;
diff --git a/source/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c
index 9dc2a18..73b14d4 100644
--- a/source/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c
+++ b/source/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#include <netdb.h>
 
 #include <gtk/gtk.h>
 #include <glib/gprintf.h>
@@ -439,7 +440,7 @@ static void callback_do_join(GtkWidget *widget,
 					 state->password,
 					 unjoin_flags);
 		if (status != 0) {
-			err_str = libnetapi_errstr(status);
+			err_str = libnetapi_get_error_string(state->ctx, status);
 			g_print("callback_do_join: failed to unjoin (%s)\n",
 				err_str);
 
@@ -463,7 +464,7 @@ static void callback_do_join(GtkWidget *widget,
 			       state->password,
 			       join_flags);
 	if (status != 0) {
-		err_str = libnetapi_errstr(status);
+		err_str = libnetapi_get_error_string(state->ctx, status);
 		g_print("callback_do_join: failed to join (%s)\n", err_str);
 
 		dialog = gtk_message_dialog_new(GTK_WINDOW(state->window_parent),
@@ -1263,37 +1264,56 @@ static int initialize_join_state(struct join_state *state,
 	{
 		char my_hostname[HOST_NAME_MAX];
 		const char *p = NULL;
+		struct hostent *hp = NULL;
+
 		if (gethostname(my_hostname, sizeof(my_hostname)) == -1) {
 			return -1;
 		}
 
-		state->my_fqdn = strdup(my_hostname);
+		p = strchr(my_hostname, '.');
+		if (p) {
+			my_hostname[strlen(my_hostname)-strlen(p)] = '\0';
+		}
+		state->my_hostname = strdup(my_hostname);
+		if (!state->my_hostname) {
+			return -1;
+		}
+		debug("state->my_hostname: %s\n", state->my_hostname);
+
+		hp = gethostbyname(my_hostname);
+		if (!hp || !hp->h_name || !*hp->h_name) {
+			return -1;
+		}
+
+		state->my_fqdn = strdup(hp->h_name);
 		if (!state->my_fqdn) {
 			return -1;
 		}
+		debug("state->my_fqdn: %s\n", state->my_fqdn);
 
-		p = strchr(my_hostname, '.');
+		p = strchr(state->my_fqdn, '.');
 		if (p) {
-			my_hostname[strlen(my_hostname) - strlen(p)] = '\0';
-			state->my_hostname = strdup(my_hostname);
-			if (!state->my_hostname) {
-				return -1;
-			}
 			p++;
 			state->my_dnsdomain = strdup(p);
-			if (!state->my_dnsdomain) {
-				return -1;
-			}
+		} else {
+			state->my_dnsdomain = strdup("");
+		}
+		if (!state->my_dnsdomain) {
+			return -1;
 		}
+		debug("state->my_dnsdomain: %s\n", state->my_dnsdomain);
 	}
 
 	{
 		const char *buffer = NULL;
 		uint16_t type = 0;
 		status = NetGetJoinInformation(NULL, &buffer, &type);
-		if (status) {
+		if (status != 0) {
+			printf("NetGetJoinInformation failed with: %s\n",
+				libnetapi_get_error_string(state->ctx, status));
 			return status;
 		}
+		debug("NetGetJoinInformation gave: %s and %d\n", buffer, type);
 		state->name_buffer_initial = strdup(buffer);
 		if (!state->name_buffer_initial) {
 			return -1;
@@ -1307,7 +1327,9 @@ static int initialize_join_state(struct join_state *state,
 		uint8_t *buffer = NULL;
 
 		status = NetServerGetInfo(NULL, 1005, &buffer);
-		if (status) {
+		if (status != 0) {
+			printf("NetServerGetInfo failed with: %s\n",
+				libnetapi_get_error_string(state->ctx, status));
 			return status;
 		}
 
diff --git a/source/lib/netapi/getdc.c b/source/lib/netapi/getdc.c
index 484af04..1084ddc 100644
--- a/source/lib/netapi/getdc.c
+++ b/source/lib/netapi/getdc.c
@@ -22,6 +22,9 @@
 #include "lib/netapi/netapi.h"
 #include "libnet/libnet.h"
 
+/********************************************************************
+********************************************************************/
+
 static WERROR NetGetDCNameLocal(struct libnetapi_ctx *ctx,
 				const char *server_name,
 				const char *domain_name,
@@ -30,6 +33,9 @@ static WERROR NetGetDCNameLocal(struct libnetapi_ctx *ctx,
 	return WERR_NOT_SUPPORTED;
 }
 
+/********************************************************************
+********************************************************************/
+
 static WERROR NetGetDCNameRemote(struct libnetapi_ctx *ctx,
 				 const char *server_name,
 				 const char *domain_name,
@@ -73,6 +79,9 @@ static WERROR NetGetDCNameRemote(struct libnetapi_ctx *ctx,
 	return werr;
 }
 
+/********************************************************************
+********************************************************************/
+
 static WERROR libnetapi_NetGetDCName(struct libnetapi_ctx *ctx,
 				     const char *server_name,
 				     const char *domain_name,
@@ -91,6 +100,10 @@ static WERROR libnetapi_NetGetDCName(struct libnetapi_ctx *ctx,
 				  buffer);
 }
 
+/****************************************************************
+ NetGetDCName
+****************************************************************/
+
 NET_API_STATUS NetGetDCName(const char *server_name,
 			    const char *domain_name,
 			    uint8_t **buffer)
@@ -112,9 +125,12 @@ NET_API_STATUS NetGetDCName(const char *server_name,
 		return W_ERROR_V(werr);
 	}
 
-	return 0;
+	return NET_API_STATUS_SUCCESS;
 }
 
+/********************************************************************
+********************************************************************/
+
 static WERROR NetGetAnyDCNameLocal(struct libnetapi_ctx *ctx,
 				   const char *server_name,
 				   const char *domain_name,
@@ -123,6 +139,9 @@ static WERROR NetGetAnyDCNameLocal(struct libnetapi_ctx *ctx,
 	return WERR_NOT_SUPPORTED;
 }
 
+/********************************************************************
+********************************************************************/
+
 static WERROR NetGetAnyDCNameRemote(struct libnetapi_ctx *ctx,
 				    const char *server_name,
 				    const char *domain_name,
@@ -170,6 +189,9 @@ static WERROR NetGetAnyDCNameRemote(struct libnetapi_ctx *ctx,
 
 }
 
+/********************************************************************
+********************************************************************/
+
 static WERROR libnetapi_NetGetAnyDCName(struct libnetapi_ctx *ctx,
 					const char *server_name,
 					const char *domain_name,
@@ -188,6 +210,10 @@ static WERROR libnetapi_NetGetAnyDCName(struct libnetapi_ctx *ctx,
 				     buffer);
 }
 
+/****************************************************************
+ NetGetAnyDCName
+****************************************************************/
+
 NET_API_STATUS NetGetAnyDCName(const char *server_name,
 			       const char *domain_name,
 			       uint8_t **buffer)
@@ -209,5 +235,5 @@ NET_API_STATUS NetGetAnyDCName(const char *server_name,
 		return W_ERROR_V(werr);
 	}
 
-	return 0;
+	return NET_API_STATUS_SUCCESS;
 }
diff --git a/source/lib/netapi/joindomain.c b/source/lib/netapi/joindomain.c
index b268e41..cbfc6c0 100644
--- a/source/lib/netapi/joindomain.c
+++ b/source/lib/netapi/joindomain.c
@@ -22,6 +22,9 @@
 #include "lib/netapi/netapi.h"
 #include "libnet/libnet.h"
 
+/****************************************************************
+****************************************************************/
+
 static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx,
 				 const char *server_name,
 				 const char *domain_name,
@@ -52,6 +55,8 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx,
 		status = dsgetdcname(mem_ctx, NULL, domain_name,
 				     NULL, NULL, flags, &info);
 		if (!NT_STATUS_IS_OK(status)) {
+			libnetapi_set_error_string(mem_ctx,
+				"%s", get_friendly_nt_error_msg(status));
 			return ntstatus_to_werror(status);
 		}
 		r->in.dc_name = talloc_strdup(mem_ctx,
@@ -79,13 +84,16 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx,
 
 	werr = libnet_Join(mem_ctx, r);
 	if (!W_ERROR_IS_OK(werr) && r->out.error_string) {
-		libnetapi_set_error_string(mem_ctx, r->out.error_string);
+		libnetapi_set_error_string(mem_ctx, "%s", r->out.error_string);
 	}
 	TALLOC_FREE(r);
 
 	return werr;
 }
 
+/****************************************************************
+****************************************************************/
+
 static WERROR NetJoinDomainRemote(struct libnetapi_ctx *ctx,
 				  const char *server_name,
 				  const char *domain_name,
@@ -149,6 +157,9 @@ static WERROR NetJoinDomainRemote(struct libnetapi_ctx *ctx,
 	return werr;
 }
 
+/****************************************************************
+****************************************************************/
+
 static WERROR libnetapi_NetJoinDomain(struct libnetapi_ctx *ctx,
 				      const char *server_name,
 				      const char *domain_name,
@@ -181,6 +192,10 @@ static WERROR libnetapi_NetJoinDomain(struct libnetapi_ctx *ctx,
 				   join_flags);
 }
 
+/****************************************************************
+ NetJoinDomain
+****************************************************************/
+
 NET_API_STATUS NetJoinDomain(const char *server_name,
 			     const char *domain_name,
 			     const char *account_ou,
@@ -208,9 +223,12 @@ NET_API_STATUS NetJoinDomain(const char *server_name,
 		return W_ERROR_V(werr);
 	}
 
-	return 0;
+	return NET_API_STATUS_SUCCESS;
 }
 
+/****************************************************************
+****************************************************************/
+
 static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx,
 				   const char *server_name,
 				   const char *account,
@@ -232,7 +250,6 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx,
 		r->in.dc_name = talloc_strdup(mem_ctx, server_name);
 		W_ERROR_HAVE_NO_MEMORY(r->in.dc_name);
 	} else {
-
 		NTSTATUS status;
 		const char *domain = NULL;
 		struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
@@ -247,6 +264,8 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx,
 		status = dsgetdcname(mem_ctx, NULL, domain,
 				     NULL, NULL, flags, &info);
 		if (!NT_STATUS_IS_OK(status)) {
+			libnetapi_set_error_string(mem_ctx,
+				"%s", get_friendly_nt_error_msg(status));
 			return ntstatus_to_werror(status);
 		}
 		r->in.dc_name = talloc_strdup(mem_ctx,
@@ -266,13 +285,22 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx,
 
 	r->in.unjoin_flags = unjoin_flags;
 	r->in.modify_config = true;
+	r->in.debug = true;
 
 	r->in.domain_sid = &domain_sid;
 
-	return libnet_Unjoin(mem_ctx, r);
+	werr = libnet_Unjoin(mem_ctx, r);
+	if (!W_ERROR_IS_OK(werr) && r->out.error_string) {
+		libnetapi_set_error_string(mem_ctx, "%s", r->out.error_string);
+	}
+	TALLOC_FREE(r);
 
+	return werr;
 }
 
+/****************************************************************
+****************************************************************/
+
 static WERROR NetUnjoinDomainRemote(struct libnetapi_ctx *ctx,
 				    const char *server_name,
 				    const char *account,
@@ -335,6 +363,9 @@ static WERROR NetUnjoinDomainRemote(struct libnetapi_ctx *ctx,
 	return werr;
 }


-- 
Samba Shared Repository


More information about the samba-cvs mailing list