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