Ejemplo n.º 1
0
JSBool netjoindomain(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
	JSString * serverStr = NULL, * domainStr = NULL, *accountOUStr = NULL, *accountStr = NULL, *passwordStr = NULL;
	DWORD joinOptions = 0;

	JS_BeginRequest(cx);
	if(!JS_ConvertArguments(cx, argc, argv, "S S S S u", &domainStr, &accountOUStr, &accountStr, &passwordStr, &joinOptions))
	{
		JS_ReportError(cx, "Unable to parse arguments in netjoindomain");
		JS_EndRequest(cx);
		return JS_FALSE;
	}

	JS_YieldRequest(cx);
	DWORD result = NetJoinDomain(NULL, (LPWSTR)JS_GetStringChars(domainStr), (JSVAL_IS_NULL(argv[1]) ? NULL : (LPWSTR)JS_GetStringChars(accountOUStr)),
		(JSVAL_IS_NULL(argv[2]) ? NULL : (LPWSTR)JS_GetStringChars(accountStr)), (JSVAL_IS_NULL(argv[3]) ? NULL : (LPWSTR)JS_GetStringChars(passwordStr)), 
		joinOptions);
	if(result == NERR_Success)
	{
		*rval = JSVAL_TRUE;
		return JS_TRUE;
	}
	JSBool retBool = JS_NewNumberValue(cx, result, rval);
	JS_EndRequest(cx);
	return retBool;
}
Ejemplo n.º 2
0
static int net_dom_join(struct net_context *c, int argc, const char **argv)
{
	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 = NETSETUP_ACCT_CREATE |
			      NETSETUP_JOIN_DOMAIN;
	struct cli_state *cli = NULL;
	bool do_reboot = false;
	NTSTATUS ntstatus;
	NET_API_STATUS status;
	int ret = -1;
	int i;

	if (argc < 1 || c->display_usage) {
		return net_dom_usage(c, argc, argv);
	}

	if (c->opt_host) {
		server_name = c->opt_host;
	}

	if (c->opt_force) {
		join_flags |= NETSETUP_DOMAIN_JOIN_IF_JOINED;
	}

	for (i=0; i<argc; i++) {
		if (strnequal(argv[i], "ou", strlen("ou"))) {
			account_ou = get_string_param(argv[i]);
			if (!account_ou) {
				return -1;
			}
		}
		if (strnequal(argv[i], "domain", strlen("domain"))) {
			domain_name = get_string_param(argv[i]);
			if (!domain_name) {
				return -1;
			}
		}
		if (strnequal(argv[i], "account", strlen("account"))) {
			Account = get_string_param(argv[i]);
			if (!Account) {
				return -1;
			}
		}
		if (strnequal(argv[i], "password", strlen("password"))) {
			password = get_string_param(argv[i]);
			if (!password) {
				return -1;
			}
		}
		if (strequal(argv[i], "reboot")) {
			do_reboot = true;
		}
	}

	if (do_reboot) {
		ntstatus = net_make_ipc_connection_ex(c, c->opt_workgroup,
						      server_name, NULL, 0,
						      &cli);
		if (!NT_STATUS_IS_OK(ntstatus)) {
			return -1;
		}
	}

	/* check if domain is a domain or a workgroup */

	status = NetJoinDomain(server_name, domain_name, account_ou,
			       Account, password, join_flags);
	if (status != 0) {
		printf("Failed to join domain: %s\n",
			libnetapi_get_error_string(c->netapi_ctx, status));
		goto done;
	}

	if (do_reboot) {
		c->opt_comment = "Shutting down due to a domain membership "
				 "change";
		c->opt_reboot = true;
		c->opt_timeout = 30;

		ret = run_rpc_command(c, cli, &ndr_table_initshutdown.syntax_id, 0,
				      rpc_init_shutdown_internals,
				      argc, argv);
		if (ret == 0) {
			goto done;
		}

		ret = run_rpc_command(c, cli, &ndr_table_winreg.syntax_id, 0,
				      rpc_reg_shutdown_internals,
				      argc, argv);
		goto done;
	}

	ret = 0;

 done:
	if (cli) {
		cli_shutdown(cli);
	}

	return ret;
}