2 * Unix SMB/CIFS implementation.
3 * Join Support (cmdline + netapi)
4 * Copyright (C) Guenther Deschner 2008
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 char *get_string_param(const char *param)
30 p = strchr(param, '=');
38 int main(int argc, char **argv)
40 NET_API_STATUS status;
41 const char *server_name = NULL;
42 const char *domain_name = NULL;
43 const char *account = NULL;
44 const char *password = NULL;
45 const char **ous = NULL;
47 struct libnetapi_ctx *ctx = NULL;
50 status = libnetapi_init(&ctx);
56 printf("usage: getjoinableous\n");
57 printf("\t<hostname> [domain=DOMAIN] <user=USER> <password=PASSWORD>\n");
62 server_name = argv[1];
65 for (i=0; i<argc; i++) {
66 if (strncasecmp(argv[i], "domain", strlen("domain"))== 0) {
67 domain_name = get_string_param(argv[i]);
69 if (strncasecmp(argv[i], "user", strlen("user"))== 0) {
70 account = get_string_param(argv[i]);
71 libnetapi_set_username(ctx, account);
73 if (strncasecmp(argv[i], "password", strlen("password"))== 0) {
74 password = get_string_param(argv[i]);
75 libnetapi_set_password(ctx, password);
77 if (strncasecmp(argv[i], "debug", strlen("debug"))== 0) {
78 const char *str = NULL;
79 str = get_string_param(argv[i]);
80 libnetapi_set_debuglevel(ctx, str);
84 status = NetGetJoinableOUs(server_name,
91 printf("failed with: %s\n",
92 libnetapi_get_error_string(ctx, status));
94 printf("Successfully queried joinable ous:\n");
95 for (i=0; i<num_ous; i++) {
96 printf("ou: %s\n", ous[i]);
100 NetApiBufferFree(ous);