From ad2974cd05b4d08c8b92f505bf95aa8e8533235f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 24 Nov 2001 14:16:41 +0000 Subject: added "net join" command this completes the first stage of the smbd ADS support (This used to be commit 058a5aee901e6609969ef7e1d482a720a84a4a12) --- source3/utils/net_join.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 source3/utils/net_join.c (limited to 'source3/utils/net_join.c') diff --git a/source3/utils/net_join.c b/source3/utils/net_join.c new file mode 100644 index 0000000000..793d72ac7e --- /dev/null +++ b/source3/utils/net_join.c @@ -0,0 +1,143 @@ +/* + Samba Unix/Linux SMB client library + Version 3.0 + join a realm + Copyright (C) 2001 Andrew Tridgell (tridge@samba.org) + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#if HAVE_ADS + +/* a lame random number generator - used /dev/urandom if possible */ +static unsigned one_random(void) +{ + int fd = -1; + static int initialised; + unsigned ret; + + if (!initialised) { + initialised = 1; + fd = open("/dev/urandom", O_RDONLY); + srandom(time(NULL) ^ getpid()); + } + + if (fd == -1) { + return random(); + } + + read(fd, &ret, sizeof(ret)); + return ret; +} + +/* + * Generate a simple random password of 15 chars - not a cryptographic one + */ +static char *generate_random_password(int len) +{ + int i; + char *pass; + + if (!(pass = malloc(len+1))) + return NULL; + + for (i=0; i Date: Wed, 28 Nov 2001 23:54:07 +0000 Subject: fixed some krb5 ifdefs (This used to be commit 23ef22f11700bbaa5778a9678a990a2b041fcefe) --- source3/utils/net_join.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_join.c') diff --git a/source3/utils/net_join.c b/source3/utils/net_join.c index 793d72ac7e..883ff3ffa6 100644 --- a/source3/utils/net_join.c +++ b/source3/utils/net_join.c @@ -21,7 +21,7 @@ #include "includes.h" -#if HAVE_ADS +#ifdef HAVE_ADS /* a lame random number generator - used /dev/urandom if possible */ static unsigned one_random(void) -- cgit From fe64484824d8169bf66822ebf7f6a9180a238e6e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 29 Nov 2001 06:21:56 +0000 Subject: Make better use of the ads_init() function to get the kerberos relam etc. This allows us to use automagically obtained values in future, and the value from krb5.conf now. Also fix mem leaks etc. Andrew Bartlett (This used to be commit 8f9ce717819235d98a1463f20ac659cb4b4ebbd2) --- source3/utils/net_join.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'source3/utils/net_join.c') diff --git a/source3/utils/net_join.c b/source3/utils/net_join.c index 883ff3ffa6..7456e54364 100644 --- a/source3/utils/net_join.c +++ b/source3/utils/net_join.c @@ -76,7 +76,6 @@ int net_join(int argc, const char **argv) { char *ldap_host; char *hostname; - char *realm; ADS_STRUCT *ads; int rc; char *password; @@ -85,10 +84,7 @@ int net_join(int argc, const char **argv) hostname = strdup(global_myname); strlower(hostname); - realm = lp_realm(); - ldap_host = lp_ads_server(); if (!*ldap_host) ldap_host = NULL; - if (!*realm) realm = NULL; if (!secrets_init()) { DEBUG(1,("Failed to initialise secrets database\n")); @@ -97,33 +93,38 @@ int net_join(int argc, const char **argv) password = generate_random_password(15); - ads = ads_init(realm, ldap_host, NULL); + ads = ads_init(NULL, NULL, NULL); rc = ads_connect(ads); if (rc) { d_printf("ads_connect: %s\n", ads_errstr(rc)); + ads_destory(&ads); return -1; } rc = ads_join_realm(ads, hostname); if (rc) { d_printf("ads_join_realm: %s\n", ads_errstr(rc)); + ads_destory(&ads); return -1; } status = ads_set_machine_password(ads, hostname, password); if (!NT_STATUS_IS_OK(status)) { d_printf("ads_set_machine_password: %s\n", get_nt_error_msg(status)); + ads_destory(&ads); return -1; } if (!secrets_store_machine_password(password)) { DEBUG(1,("Failed to save machine password\n")); + ads_destory(&ads); return -1; } - d_printf("Joined %s to realm %s\n", hostname, realm); + d_printf("Joined %s to realm %s\n", hostname, ads->realm); + ads_destory(&ads); return 0; } -- cgit From e573bfa386c80c9a7a9c5a86d9eb15eaa7da398a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 1 Dec 2001 03:26:57 +0000 Subject: not used any more (This used to be commit 97627e424a1de3df0a6f7a9bfaaf3ece4dd2036d) --- source3/utils/net_join.c | 144 ----------------------------------------------- 1 file changed, 144 deletions(-) delete mode 100644 source3/utils/net_join.c (limited to 'source3/utils/net_join.c') diff --git a/source3/utils/net_join.c b/source3/utils/net_join.c deleted file mode 100644 index 7456e54364..0000000000 --- a/source3/utils/net_join.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - Samba Unix/Linux SMB client library - Version 3.0 - join a realm - Copyright (C) 2001 Andrew Tridgell (tridge@samba.org) - - 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 2 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" - -#ifdef HAVE_ADS - -/* a lame random number generator - used /dev/urandom if possible */ -static unsigned one_random(void) -{ - int fd = -1; - static int initialised; - unsigned ret; - - if (!initialised) { - initialised = 1; - fd = open("/dev/urandom", O_RDONLY); - srandom(time(NULL) ^ getpid()); - } - - if (fd == -1) { - return random(); - } - - read(fd, &ret, sizeof(ret)); - return ret; -} - -/* - * Generate a simple random password of 15 chars - not a cryptographic one - */ -static char *generate_random_password(int len) -{ - int i; - char *pass; - - if (!(pass = malloc(len+1))) - return NULL; - - for (i=0; irealm); - - ads_destory(&ads); - return 0; -} - -#else - -int net_join_usage(void) -{ - d_printf("ADS support not compiled in\n"); - return -1; -} - -int net_join(int argc, const char **argv) -{ - return net_join_usage(); -} - -#endif -- cgit From 666292129b1cb7df2f3162736d40b53513313139 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Tue, 13 May 2008 11:11:35 +0200 Subject: net: Move "net join" handling into a separate file. (This used to be commit d0237a736858a48494583ce7f960ea980768aa6c) --- source3/utils/net_join.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 source3/utils/net_join.c (limited to 'source3/utils/net_join.c') diff --git a/source3/utils/net_join.c b/source3/utils/net_join.c new file mode 100644 index 0000000000..98188aae5f --- /dev/null +++ b/source3/utils/net_join.c @@ -0,0 +1,54 @@ +/* + Samba Unix/Linux SMB client library + net join commands + Copyright (C) 2002 Jim McDonough (jmcd@us.ibm.com) + Copyright (C) 2008 Kai Blin (kai@samba.org) + + 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 "includes.h" +#include "utils/net.h" + +int net_join_usage(struct net_context *c, int argc, const char **argv) +{ + d_printf("\nnet [] join [misc. options]\n" + "\tjoins this server to a domain\n"); + d_printf("Valid methods: (auto-detected if not specified)\n"); + d_printf("\tads\t\t\t\tActive Directory (LDAP/Kerberos)\n"); + d_printf("\trpc\t\t\t\tDCE-RPC\n"); + net_common_flags_usage(c, argc, argv); + return -1; +} + +int net_join(struct net_context *c, int argc, const char **argv) +{ + if (argc < 1) + return net_join_usage(c, argc, argv); + + if (StrCaseCmp(argv[0], "HELP") == 0) { + net_join_usage(c, argc, argv); + return 0; + } + + if (net_ads_check_our_domain(c) == 0) { + if (net_ads_join(c, argc, argv) == 0) + return 0; + else + d_fprintf(stderr, "ADS join did not work, falling back to RPC...\n"); + } + return net_rpc_join(c, argc, argv); +} + + -- cgit