Example #1
0
File: authz.c Project: rcarz/bonsai
/**
 * Initialises the NetApi context. This function is not re-entrant.
 *
 * @param host      hostname of the Samba server
 * @param username  service account username
 * @param passwd    service account password
 *
 * @return true on success, false otherwise
 */
int authz_init(const char *host, const char *username, const char *passwd)
{
    pthread_mutex_lock(&_ctxmtx);

    if (_netapictx || !host || !username || !passwd) {
        pthread_mutex_unlock(&_ctxmtx);
        return 0;
    }

    if (libnetapi_init(&_netapictx) != NET_API_STATUS_SUCCESS) {
        log_error("failed to initialise NetApi context");
        pthread_mutex_unlock(&_ctxmtx);
        return 0;
    }

    libnetapi_set_username(_netapictx, username);
    libnetapi_set_password(_netapictx, passwd);

    _host = strdup(host);

    pthread_mutex_unlock(&_ctxmtx);
    log_info("initialised NetApi context");

    return 1;
}
Example #2
0
int main(int argc, const char **argv)
{
    NET_API_STATUS status;
    struct libnetapi_ctx *ctx = NULL;

    const char *hostname = NULL;
    const char *domain = NULL;
    uint8_t *buffer = NULL;

    poptContext pc;
    int opt;

    struct poptOption long_options[] = {
        POPT_AUTOHELP
        POPT_COMMON_LIBNETAPI_EXAMPLES
        POPT_TABLEEND
    };

    status = libnetapi_init(&ctx);
    if (status != 0) {
        return status;
    }

    pc = poptGetContext("getdc", argc, argv, long_options, 0);

    poptSetOtherOptionHelp(pc, "hostname domainname");
    while((opt = poptGetNextOpt(pc)) != -1) {
    }

    if (!poptPeekArg(pc)) {
        poptPrintHelp(pc, stderr, 0);
        goto out;
    }
    hostname = poptGetArg(pc);

    if (!poptPeekArg(pc)) {
        poptPrintHelp(pc, stderr, 0);
        goto out;
    }
    domain = poptGetArg(pc);

    /* NetGetDCName */

    status = NetGetDCName(hostname, domain, &buffer);
    if (status != 0) {
        printf("GetDcName failed with: %s\n", libnetapi_errstr(status));
    } else {
        printf("%s\n", (char *)buffer);
    }

out:
    NetApiBufferFree(buffer);
    libnetapi_free(ctx);
    poptFreeContext(pc);

    return status;
}
Example #3
0
NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx)
{
	if (stat_ctx) {
		*ctx = stat_ctx;
		return NET_API_STATUS_SUCCESS;
	}

	return libnetapi_init(ctx);
}
Example #4
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	const char *sharename = NULL;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("share_del", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname sharename");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	sharename = poptGetArg(pc);

	/* NetShareDel */

	status = NetShareDel(hostname,
			     sharename,
			     0);
	if (status != 0) {
		printf("NetShareDel failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
		goto out;
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Example #5
0
static bool torture_libnetapi_initialize(struct torture_context *tctx)
{
        NET_API_STATUS status;
	struct libnetapi_ctx *ctx;

	/* We must do this first, as otherwise we fail if we don't
	 * have an smb.conf in the default path (we need to use the
	 * torture smb.conf */
	torture_assert(tctx, torture_libnetapi_init_context(tctx, &ctx),
		       "failed to initialize libnetapi");

	status = libnetapi_init(&ctx);

	torture_assert(tctx, ctx != NULL, "Failed to get a libnetapi_ctx");
	torture_assert_int_equal(tctx, status, 0, "libnetapi_init failed despite alredy being set up");

	libnetapi_free(ctx);

	return true;
}
Example #6
0
int net_dom(struct net_context *c, int argc, const char **argv)
{
	NET_API_STATUS status;

	struct functable func[] = {
		{
			"join",
			net_dom_join,
			NET_TRANSPORT_LOCAL,
			"Join a remote machine",
			"net dom join <domain=DOMAIN> <ou=OU> "
			"<account=ACCOUNT> <password=PASSWORD> <reboot>\n"
			"  Join a remote machine"
		},
		{
			"unjoin",
			net_dom_unjoin,
			NET_TRANSPORT_LOCAL,
			"Unjoin a remote machine",
			"net dom unjoin <account=ACCOUNT> <password=PASSWORD> "
			"<reboot>\n"
			"  Unjoin a remote machine"
		},
		{NULL, NULL, 0, NULL, NULL}
	};

	status = libnetapi_init(&c->netapi_ctx);
	if (status != 0) {
		return -1;
	}

	libnetapi_set_username(c->netapi_ctx, c->opt_user_name);
	libnetapi_set_password(c->netapi_ctx, c->opt_password);
	if (c->opt_kerberos) {
		libnetapi_set_use_kerberos(c->netapi_ctx);
	}

	return net_run_function(c, argc, argv, "net dom", func);
}
Example #7
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	uint32_t level = 0;
	uint8_t *buffer = NULL;
	uint32_t entries_read = 0;
	uint32_t total_entries = 0;
	uint32_t resume_handle = 0;
	int i;

	struct SHARE_INFO_0 *i0 = NULL;
	struct SHARE_INFO_1 *i1 = NULL;
	struct SHARE_INFO_2 *i2 = NULL;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("share_enum", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname level");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (poptPeekArg(pc)) {
		level = atoi(poptGetArg(pc));
	}

	/* NetShareEnum */

	do {
		status = NetShareEnum(hostname,
				      level,
				      &buffer,
				      (uint32_t)-1,
				      &entries_read,
				      &total_entries,
				      &resume_handle);
		if (status == 0 || status == ERROR_MORE_DATA) {
			printf("total entries: %d\n", total_entries);
			switch (level) {
				case 0:
					i0 = (struct SHARE_INFO_0 *)buffer;
					break;
				case 1:
					i1 = (struct SHARE_INFO_1 *)buffer;
					break;
				case 2:
					i2 = (struct SHARE_INFO_2 *)buffer;
					break;
				default:
					break;
			}
			for (i=0; i<entries_read; i++) {
				switch (level) {
					case 0:
						printf("#%d netname: %s\n", i, i0->shi0_netname);
						i0++;
						break;
					case 1:
						printf("#%d netname: %s\n", i, i1->shi1_netname);
						printf("#%d type: %d\n", i, i1->shi1_type);
						printf("#%d remark: %s\n", i, i1->shi1_remark);
						i1++;
						break;
					case 2:
						printf("#%d netname: %s\n", i, i2->shi2_netname);
						printf("#%d type: %d\n", i, i2->shi2_type);
						printf("#%d remark: %s\n", i, i2->shi2_remark);
						printf("#%d permissions: %d\n", i, i2->shi2_permissions);
						printf("#%d max users: %d\n", i, i2->shi2_max_uses);
						printf("#%d current users: %d\n", i, i2->shi2_current_uses);
						printf("#%d path: %s\n", i, i2->shi2_path);
						printf("#%d password: %s\n", i, i2->shi2_passwd);
						i2++;
						break;
					default:
						break;
				}
			}
			NetApiBufferFree(buffer);
		}
	} while (status == ERROR_MORE_DATA);

	if (status != 0) {
		printf("NetShareEnum failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Example #8
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	const char *sharename = NULL;
	const char *comment = "NetApi generated Share comment";
	uint32_t level = 1004;
	uint8_t *buffer = NULL;
	uint32_t parm_err = 0;

	struct SHARE_INFO_1004 i1004;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("share_setinfo", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname sharename comment");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	sharename = poptGetArg(pc);

	if (poptPeekArg(pc)) {
		comment = poptGetArg(pc);
	}

	/* NetShareSetInfo */
	switch (level) {
		case 1004:
			i1004.shi1004_remark = comment;
			buffer = (uint8_t *)&i1004;
			break;
		default:
			break;
	}

	status = NetShareSetInfo(hostname,
				 sharename,
				 level,
				 buffer,
				 &parm_err);
	if (status != 0) {
		printf("NetShareSetInfo failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
		goto out;
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Example #9
0
int net_rpc_shell(struct net_context *c, int argc, const char **argv)
{
	NTSTATUS status;
	struct rpc_sh_ctx *ctx;

	if (argc != 0 || c->display_usage) {
		d_printf("Usage:\n"
			 "net rpc shell\n");
		return -1;
	}

	if (libnetapi_init(&c->netapi_ctx) != 0) {
		return -1;
	}
	libnetapi_set_username(c->netapi_ctx, c->opt_user_name);
	libnetapi_set_password(c->netapi_ctx, c->opt_password);
	if (c->opt_kerberos) {
		libnetapi_set_use_kerberos(c->netapi_ctx);
	}

	ctx = TALLOC_P(NULL, struct rpc_sh_ctx);
	if (ctx == NULL) {
		d_fprintf(stderr, "talloc failed\n");
		return -1;
	}

	status = net_make_ipc_connection(c, 0, &(ctx->cli));
	if (!NT_STATUS_IS_OK(status)) {
		d_fprintf(stderr, "Could not open connection: %s\n",
			  nt_errstr(status));
		return -1;
	}

	ctx->cmds = sh_cmds;
	ctx->whoami = "net rpc";
	ctx->parent = NULL;

	status = net_get_remote_domain_sid(ctx->cli, ctx, &ctx->domain_sid,
					   &ctx->domain_name);
	if (!NT_STATUS_IS_OK(status)) {
		return -1;
	}

	d_printf("Talking to domain %s (%s)\n", ctx->domain_name,
		 sid_string_tos(ctx->domain_sid));

	this_ctx = ctx;

	while(1) {
		char *prompt = NULL;
		char *line = NULL;
		int ret;

		if (asprintf(&prompt, "%s> ", this_ctx->whoami) < 0) {
			break;
		}

		line = smb_readline(prompt, NULL, completion_fn);
		SAFE_FREE(prompt);

		if (line == NULL) {
			break;
		}

		ret = poptParseArgvString(line, &argc, &argv);
		if (ret == POPT_ERROR_NOARG) {
			SAFE_FREE(line);
			continue;
		}
		if (ret != 0) {
			d_fprintf(stderr, "cmdline invalid: %s\n",
				  poptStrerror(ret));
			SAFE_FREE(line);
			return false;
		}

		if ((line[0] != '\n') &&
		    (!net_sh_process(c, this_ctx, argc, argv))) {
			SAFE_FREE(line);
			break;
		}
		SAFE_FREE(line);
	}

	cli_shutdown(ctx->cli);

	TALLOC_FREE(ctx);

	return 0;
}
Example #10
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	const char *username = NULL;
	uint32_t level = 0;
	uint8_t *buffer = NULL;
	uint32_t entries_read = 0;
	uint32_t total_entries = 0;
	int i;

	struct GROUP_USERS_INFO_0 *info0 = NULL;
	struct GROUP_USERS_INFO_1 *info1 = NULL;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("user_getgroups", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname username level");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	username = poptGetArg(pc);

	if (poptPeekArg(pc)) {
		level = atoi(poptGetArg(pc));
	}

	/* NetUserGetGroups */

	do {
		status = NetUserGetGroups(hostname,
					  username,
					  level,
					  &buffer,
					  (uint32_t)-1,
					  &entries_read,
					  &total_entries);
		if (status == 0 || status == ERROR_MORE_DATA) {

			switch (level) {
				case 0:
					info0 = (struct GROUP_USERS_INFO_0 *)buffer;
					break;
				case 1:
					info1 = (struct GROUP_USERS_INFO_1 *)buffer;
					break;
				default:
					break;
			}

			for (i=0; i<entries_read; i++) {
				switch (level) {
					case 0:
						printf("#%d group: %s\n", i, info0->grui0_name);
						info0++;
						break;
					case 1:
						printf("#%d group: %s\n", i, info1->grui1_name);
						printf("#%d attributes: %d\n", i, info1->grui1_attributes);
						info1++;
						break;
					default:
						break;
				}
			}
			NetApiBufferFree(buffer);
		}
	} while (status == ERROR_MORE_DATA);

	if (status != 0) {
		printf("NetUserGetGroups failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Example #11
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	const char *groupname = NULL;
	struct LOCALGROUP_MEMBERS_INFO_0 *g0;
	struct LOCALGROUP_MEMBERS_INFO_3 *g3;
	uint32_t total_entries = 0;
	uint8_t *buffer = NULL;
	uint32_t level = 3;
	const char **names = NULL;
	int i = 0;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("localgroup_addmembers", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname groupname member1 member2 ...");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	groupname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}

	names = poptGetArgs(pc);
	for (i=0; names[i] != NULL; i++) {
		total_entries++;
	}

	switch (level) {
		case 0:
			status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries,
						      (void **)&g0);
			if (status) {
				printf("NetApiBufferAllocate failed with: %s\n",
					libnetapi_get_error_string(ctx, status));
				goto out;
			}

			for (i=0; i<total_entries; i++) {
				if (!ConvertStringSidToSid(names[i], &g0[i].lgrmi0_sid)) {
					printf("could not convert sid\n");
					goto out;
				}
			}

			buffer = (uint8_t *)g0;
			break;
		case 3:
			status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_3) * total_entries,
						      (void **)&g3);
			if (status) {
				printf("NetApiBufferAllocate failed with: %s\n",
					libnetapi_get_error_string(ctx, status));
				goto out;
			}

			for (i=0; i<total_entries; i++) {
				g3[i].lgrmi3_domainandname = names[i];
			}

			buffer = (uint8_t *)g3;
			break;
		default:
			break;
	}

	/* NetLocalGroupAddMembers */

	status = NetLocalGroupAddMembers(hostname,
					 groupname,
					 level,
					 buffer,
					 total_entries);
	if (status != 0) {
		printf("NetLocalGroupAddMembers failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Example #12
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	const char *username = NULL;
	uint32_t level = 0;
	uint32_t parm_err = 0;
	uint8_t *buffer = NULL;
	const char *val = NULL;

	struct USER_INFO_0 u0;
	struct USER_INFO_1 u1;
	struct USER_INFO_2 u2;
	struct USER_INFO_3 u3;
	struct USER_INFO_4 u4;
	struct USER_INFO_21 u21;
	struct USER_INFO_22 u22;
	struct USER_INFO_1003 u1003;
	struct USER_INFO_1005 u1005;
	struct USER_INFO_1006 u1006;
	struct USER_INFO_1007 u1007;
	struct USER_INFO_1008 u1008;
	struct USER_INFO_1009 u1009;
	struct USER_INFO_1010 u1010;
	struct USER_INFO_1011 u1011;
	struct USER_INFO_1012 u1012;
	struct USER_INFO_1014 u1014;
	struct USER_INFO_1017 u1017;
	struct USER_INFO_1020 u1020;
	struct USER_INFO_1024 u1024;
	struct USER_INFO_1051 u1051;
	struct USER_INFO_1052 u1052;
	struct USER_INFO_1053 u1053;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("user_setinfo", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname username level");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	username = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	level = atoi(poptGetArg(pc));

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	val = poptGetArg(pc);

	/* NetUserSetInfo */

	switch (level) {
		case 0:
			u0.usri0_name = val;
			buffer = (uint8_t *)&u0;
			break;
		case 1:
		case 2:
		case 3:
		case 4:
			break;
		case 21:
			break;
		case 22:
			break;
		case 1003:
			u1003.usri1003_password = val;
			buffer = (uint8_t *)&u1003;
			break;
		case 1005:
			u1005.usri1005_priv = atoi(val);
			buffer = (uint8_t *)&u1005;
			break;
		case 1006:
			u1006.usri1006_home_dir = val;
			buffer = (uint8_t *)&u1006;
			break;
		case 1007:
			u1007.usri1007_comment = val;
			buffer = (uint8_t *)&u1007;
			break;
		case 1008:
			u1008.usri1008_flags = atoi(val);
			buffer = (uint8_t *)&u1008;
			break;
		case 1009:
			u1009.usri1009_script_path = val;
			buffer = (uint8_t *)&u1009;
			break;
		case 1010:
			u1010.usri1010_auth_flags = atoi(val);
			buffer = (uint8_t *)&u1010;
			break;
		case 1011:
			u1011.usri1011_full_name = val;
			buffer = (uint8_t *)&u1011;
			break;
		case 1012:
			u1012.usri1012_usr_comment = val;
			buffer = (uint8_t *)&u1012;
			break;
		case 1014:
			u1014.usri1014_workstations = val;
			buffer = (uint8_t *)&u1014;
			break;
		case 1017:
			u1017.usri1017_acct_expires = atoi(val);
			buffer = (uint8_t *)&u1017;
			break;
		case 1020:
			break;
		case 1024:
			u1024.usri1024_country_code = atoi(val);
			buffer = (uint8_t *)&u1024;
			break;
		case 1051:
			u1051.usri1051_primary_group_id = atoi(val);
			buffer = (uint8_t *)&u1051;
			break;
		case 1052:
			u1052.usri1052_profile = val;
			buffer = (uint8_t *)&u1052;
			break;
		case 1053:
			u1053.usri1053_home_dir_drive = val;
			buffer = (uint8_t *)&u1053;
			break;
		default:
			break;
	}

	status = NetUserSetInfo(hostname,
				username,
				level,
				buffer,
				&parm_err);
	if (status != 0) {
		printf("NetUserSetInfo failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
		goto out;
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
int main(int argc, const char **argv)
{
	NET_API_STATUS status = 0;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("netapitest", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	status = netapitest_localgroup(ctx, hostname);
	if (status) {
		goto out;
	}

	status = netapitest_user(ctx, hostname);
	if (status) {
		goto out;
	}

	status = netapitest_group(ctx, hostname);
	if (status) {
		goto out;
	}

	status = netapitest_display(ctx, hostname);
	if (status) {
		goto out;
	}

	status = netapitest_share(ctx, hostname);
	if (status) {
		goto out;
	}

	status = netapitest_file(ctx, hostname);
	if (status) {
		goto out;
	}

 out:
	if (status != 0) {
		printf("testsuite failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
	}

	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Example #14
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	const char *username = NULL;
	const char *password = NULL;
	struct USER_INFO_1 info1;
	uint32_t parm_error = 0;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("user_add", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname username password");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	username = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	password = poptGetArg(pc);

	/* NetUserAdd */

	info1.usri1_name = username;
	info1.usri1_password = password;
	info1.usri1_password_age = 0;
	info1.usri1_priv = 0;
	info1.usri1_home_dir = NULL;
	info1.usri1_comment = "User created using Samba NetApi Example code";
	info1.usri1_flags = 0;
	info1.usri1_script_path = NULL;

	status = NetUserAdd(hostname,
			    1,
			    (uint8_t *)&info1,
			    &parm_error);
	if (status != 0) {
		printf("NetUserAdd failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Example #15
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	uint8_t *buffer = NULL;
	uint32_t entries_read = 0;
	uint32_t total_entries = 0;
	uint32_t resume_handle = 0;
	int i;

	struct USER_INFO_0 *info0;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("user_enum", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	/* NetUserEnum */

	do {
		status = NetUserEnum(hostname,
				     0,
				     0,
				     &buffer,
				     (uint32_t)-1,
				     &entries_read,
				     &total_entries,
				     &resume_handle);
		if (status == 0 || status == ERROR_MORE_DATA) {
			info0 = (struct USER_INFO_0 *)buffer;
			for (i=0; i<entries_read; i++) {
				printf("user %d: %s\n", i, info0->usri0_name);
				info0++;
			}
			NetApiBufferFree(buffer);
		}
	} while (status == ERROR_MORE_DATA);

	if (status != 0) {
		printf("NetUserEnum failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}