#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <locale.h>
#include <netdb.h>
#include <limits.h>
#include <smbsrv/libsmbns.h>
#define QUOTE(x) #x
#define VAL2STR(x) QUOTE(x)
char *whoami = NULL;
static void usage();
static
void
usage()
{
fprintf(stderr,
gettext("Usage: %s [ -d fqdn ] [ -s server ]\n"), whoami);
fprintf(stderr,
gettext("\t-d\tThe fully qualified domain of the client\n"));
fprintf(stderr, gettext("\t-s\tThe domain controller to join\n"));
fprintf(stderr,
gettext("\tstdin is used to read in the password or \n"));
fprintf(stderr, gettext("\tthe password is prompted for.\n"));
exit(1);
}
int
main(int argc, char **argv)
{
char fqdn[MAXHOSTNAMELEN], server[MAXHOSTNAMELEN];
char *newpw;
int c, ret = 0;
(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
whoami = argv[0];
while ((c = getopt(argc, argv, "d:s:")) != -1) {
switch (c) {
case 'd':
(void) strncpy(fqdn, optarg, sizeof (fqdn));
break;
case 's':
(void) strncpy(server, optarg, sizeof (server));
break;
default:
usage();
break;
}
}
if (argc != optind)
usage();
if (!isatty(fileno(stdin))) {
char buf[PASS_MAX + 1];
if (scanf("%" VAL2STR(PASS_MAX) "s", &buf) != 1) {
fprintf(stderr,
gettext("Couldn't read new password\n"));
exit(1);
}
newpw = strdup(buf);
if (newpw == NULL) {
fprintf(stderr, gettext("Couldn't allocate memory\n"));
exit(1);
}
} else {
newpw = getpassphrase(gettext("Enter new password: "));
if (newpw == NULL) {
fprintf(stderr,
gettext("Couldn't read new password\n"));
exit(1);
}
newpw = strdup(newpw);
if (newpw == NULL) {
fprintf(stderr, gettext("Couldn't allocate memory\n"));
exit(1);
}
}
ret = smb_setdomainprops(fqdn, server, newpw);
free(newpw);
return (ret);
}