xref: /illumos-gate/usr/src/cmd/krb5/kadmin/kclient/ksmb.c (revision ef150c2b)
1bd211b85Ssemery /*
2bd211b85Ssemery  * CDDL HEADER START
3bd211b85Ssemery  *
4bd211b85Ssemery  * The contents of this file are subject to the terms of the
5bd211b85Ssemery  * Common Development and Distribution License (the "License").
6bd211b85Ssemery  * You may not use this file except in compliance with the License.
7bd211b85Ssemery  *
8bd211b85Ssemery  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9bd211b85Ssemery  * or http://www.opensolaris.org/os/licensing.
10bd211b85Ssemery  * See the License for the specific language governing permissions
11bd211b85Ssemery  * and limitations under the License.
12bd211b85Ssemery  *
13bd211b85Ssemery  * When distributing Covered Code, include this CDDL HEADER in each
14bd211b85Ssemery  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15bd211b85Ssemery  * If applicable, add the following below this CDDL HEADER, with the
16bd211b85Ssemery  * fields enclosed by brackets "[]" replaced with your own identifying
17bd211b85Ssemery  * information: Portions Copyright [yyyy] [name of copyright owner]
18bd211b85Ssemery  *
19bd211b85Ssemery  * CDDL HEADER END
20bd211b85Ssemery  */
21bd211b85Ssemery 
22bd211b85Ssemery /*
23bd211b85Ssemery  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24bd211b85Ssemery  * Use is subject to license terms.
25bd211b85Ssemery  */
26bd211b85Ssemery 
27bd211b85Ssemery #include <stdio.h>
28bd211b85Ssemery #include <stdlib.h>
29bd211b85Ssemery #include <strings.h>
30bd211b85Ssemery #include <locale.h>
31bd211b85Ssemery #include <netdb.h>
32bd211b85Ssemery #include <limits.h>
33bd211b85Ssemery #include <smbsrv/libsmbns.h>
34bd211b85Ssemery 
35bd211b85Ssemery #define	QUOTE(x)	#x
36bd211b85Ssemery #define	VAL2STR(x)	QUOTE(x)
37bd211b85Ssemery 
38bd211b85Ssemery char *whoami = NULL;
39bd211b85Ssemery 
40bd211b85Ssemery static void usage();
41bd211b85Ssemery 
42bd211b85Ssemery static
43bd211b85Ssemery void
usage()44bd211b85Ssemery usage()
45bd211b85Ssemery {
46bd211b85Ssemery 	fprintf(stderr,
47bd211b85Ssemery 	    gettext("Usage: %s [ -d fqdn ] [ -s server ]\n"), whoami);
48bd211b85Ssemery 	fprintf(stderr,
49bd211b85Ssemery 	    gettext("\t-d\tThe fully qualified domain of the client\n"));
50bd211b85Ssemery 	fprintf(stderr, gettext("\t-s\tThe domain controller to join\n"));
51bd211b85Ssemery 	fprintf(stderr,
52bd211b85Ssemery 	    gettext("\tstdin is used to read in the password or \n"));
53bd211b85Ssemery 	fprintf(stderr, gettext("\tthe password is prompted for.\n"));
54bd211b85Ssemery 
55bd211b85Ssemery 	exit(1);
56bd211b85Ssemery }
57bd211b85Ssemery 
58bd211b85Ssemery int
main(int argc,char ** argv)59bd211b85Ssemery main(int argc, char **argv)
60bd211b85Ssemery {
61*ef150c2bSRichard Lowe 	char fqdn[MAXHOSTNAMELEN], server[MAXHOSTNAMELEN];
62bd211b85Ssemery 	char *newpw;
63*ef150c2bSRichard Lowe 	int c, ret = 0;
64bd211b85Ssemery 
65bd211b85Ssemery 	(void) setlocale(LC_ALL, "");
66bd211b85Ssemery 
67bd211b85Ssemery #if !defined(TEXT_DOMAIN)
68bd211b85Ssemery #define	TEXT_DOMAIN "SYS_TEST"
69bd211b85Ssemery #endif /* TEXT_DOMAIN */
70bd211b85Ssemery 
71bd211b85Ssemery 	(void) textdomain(TEXT_DOMAIN);
72bd211b85Ssemery 
73bd211b85Ssemery 	whoami = argv[0];
74bd211b85Ssemery 
75bd211b85Ssemery 	while ((c = getopt(argc, argv, "d:s:")) != -1) {
76bd211b85Ssemery 		switch (c) {
77bd211b85Ssemery 		case 'd':
78bd211b85Ssemery 			(void) strncpy(fqdn, optarg, sizeof (fqdn));
79bd211b85Ssemery 			break;
80bd211b85Ssemery 		case 's':
81bd211b85Ssemery 			(void) strncpy(server, optarg, sizeof (server));
82bd211b85Ssemery 			break;
83bd211b85Ssemery 		default:
84bd211b85Ssemery 			usage();
85bd211b85Ssemery 			break;
86bd211b85Ssemery 		}
87bd211b85Ssemery 	}
88bd211b85Ssemery 
89bd211b85Ssemery 	if (argc != optind)
90bd211b85Ssemery 		usage();
91bd211b85Ssemery 
92bd211b85Ssemery 	if (!isatty(fileno(stdin))) {
93bd211b85Ssemery 		char buf[PASS_MAX + 1];
94bd211b85Ssemery 
95bd211b85Ssemery 		if (scanf("%" VAL2STR(PASS_MAX) "s", &buf) != 1) {
96bd211b85Ssemery 			fprintf(stderr,
97bd211b85Ssemery 			    gettext("Couldn't read new password\n"));
98bd211b85Ssemery 			exit(1);
99bd211b85Ssemery 		}
100bd211b85Ssemery 
101bd211b85Ssemery 		newpw = strdup(buf);
102bd211b85Ssemery 		if (newpw == NULL) {
103bd211b85Ssemery 			fprintf(stderr, gettext("Couldn't allocate memory\n"));
104bd211b85Ssemery 			exit(1);
105bd211b85Ssemery 		}
106bd211b85Ssemery 	} else {
107bd211b85Ssemery 		newpw = getpassphrase(gettext("Enter new password: "));
108bd211b85Ssemery 		if (newpw == NULL) {
109bd211b85Ssemery 			fprintf(stderr,
110bd211b85Ssemery 			    gettext("Couldn't read new password\n"));
111bd211b85Ssemery 			exit(1);
112bd211b85Ssemery 		}
113bd211b85Ssemery 
114bd211b85Ssemery 		newpw = strdup(newpw);
115bd211b85Ssemery 		if (newpw == NULL) {
116bd211b85Ssemery 			fprintf(stderr, gettext("Couldn't allocate memory\n"));
117bd211b85Ssemery 			exit(1);
118bd211b85Ssemery 		}
119bd211b85Ssemery 	}
120bd211b85Ssemery 
121bd211b85Ssemery 	/*
122bd211b85Ssemery 	 * Set the SMF properties for smb for later use.
123bd211b85Ssemery 	 */
124bd211b85Ssemery 	ret = smb_setdomainprops(fqdn, server, newpw);
125bd211b85Ssemery 
126bd211b85Ssemery 	free(newpw);
127bd211b85Ssemery 
128bd211b85Ssemery 	return (ret);
129bd211b85Ssemery }
130