From f3607f85b673ade41773fcfd2cb6935b512fbf60 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 21 Dec 2007 16:08:13 +0100 Subject: Add netdomjoin cmd line tool (another libnetapi example). Guenther (This used to be commit c502686f09713a7cf3786c254be6515a7aa23555) --- source3/lib/netapi/examples/Makefile.in | 7 +- source3/lib/netapi/examples/netdomjoin.c | 107 +++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 source3/lib/netapi/examples/netdomjoin.c (limited to 'source3/lib') diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in index 79f9187d84..d618599433 100644 --- a/source3/lib/netapi/examples/Makefile.in +++ b/source3/lib/netapi/examples/Makefile.in @@ -21,8 +21,9 @@ COMPILE = $(COMPILE_CC) $(COMPILE_CC) >/dev/null 2>&1 GETDC_OBJ = getdc.o +NETDOMJOIN_OBJ = netdomjoin.o -PROGS = getdc +PROGS = getdc netdomjoin all: $(PROGS) @@ -30,5 +31,9 @@ getdc: $(GETDC_OBJ) @echo Linking $@ @$(CC) $(FLAGS) -o $@ $(GETDC_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) +netdomjoin: $(NETDOMJOIN_OBJ) + @echo Linking $@ + @$(CC) $(FLAGS) -o $@ $(NETDOMJOIN_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) + clean: @rm -f $(PROGS) diff --git a/source3/lib/netapi/examples/netdomjoin.c b/source3/lib/netapi/examples/netdomjoin.c new file mode 100644 index 0000000000..a2bb700250 --- /dev/null +++ b/source3/lib/netapi/examples/netdomjoin.c @@ -0,0 +1,107 @@ +/* + * Unix SMB/CIFS implementation. + * Join Support (cmdline + netapi) + * Copyright (C) Guenther Deschner 2007 + * + * 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 +#include +#include +#include +#include + +#include + +char *get_string_param(const char *param) +{ + char *p; + + p = strchr(param, '='); + if (!p) { + return NULL; + } + + return (p+1); +} + +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 *password = NULL; + uint32_t join_flags = 3; + struct libnetapi_ctx *ctx = NULL; + int i; + + status = libnetapi_init(&ctx); + if (status != 0) { + return status; + } + + if (argc < 2) { + printf("usage: netdomjoin\n"); + printf("\t[hostname=HOSTNAME] [domain=DOMAIN] \n"); + return 0; + } + + if (argc > 2) { + server_name = argv[1]; + } + + for (i=0; i