Ejemplo n.º 1
0
_PUBLIC_ struct socket_address *socket_address_from_strings(TALLOC_CTX *mem_ctx,
							    const char *family,
							    const char *host,
							    int port)
{
	struct socket_address *addr = talloc(mem_ctx, struct socket_address);
	if (!addr) {
		return NULL;
	}

	if (strcmp(family, "ip") == 0 && is_ipaddress_v6(host)) {
		/* leaving as "ip" would force IPv4 */
		family = "ipv6";
	}

	addr->family = family;
	addr->addr = talloc_strdup(addr, host);
	if (!addr->addr) {
		talloc_free(addr);
		return NULL;
	}
	addr->port = port;
	addr->sockaddr = NULL;
	addr->sockaddrlen = 0;

	return addr;
}
Ejemplo n.º 2
0
/* Kill a client by IP address */
static bool do_kill_client_by_ip(struct tevent_context *ev_ctx,
				 struct messaging_context *msg_ctx,
				 const struct server_id pid,
				 const int argc, const char **argv)
{
	if (argc != 2) {
		fprintf(stderr, "Usage: smbcontrol <dest> kill-client-ip "
			"<IP address>\n");
		return false;
	}

	if (!is_ipaddress_v4(argv[1]) && !is_ipaddress_v6(argv[1])) {
		fprintf(stderr, "%s is not a valid IP address!\n", argv[1]);
		return false;
	}

	return send_message(msg_ctx, pid, MSG_SMB_KILL_CLIENT_IP,
			    argv[1], strlen(argv[1]) + 1);
}
Ejemplo n.º 3
0
bool is_ipaddress(const char *str)
{
	return is_ipaddress_v4(str) || is_ipaddress_v6(str);
}
Ejemplo n.º 4
0
/*
  parse a binding string into a dcerpc_binding structure
*/
_PUBLIC_ NTSTATUS dcerpc_parse_binding(TALLOC_CTX *mem_ctx, const char *_s, struct dcerpc_binding **b_out)
{
	char *_t;
	struct dcerpc_binding *b;
	char *s;
	char *options = NULL;
	char *p;
	size_t i;
	NTSTATUS status;

	b = talloc_zero(mem_ctx, struct dcerpc_binding);
	if (!b) {
		return NT_STATUS_NO_MEMORY;
	}

	_t = talloc_strdup(b, _s);
	if (_t == NULL) {
		talloc_free(b);
		return NT_STATUS_NO_MEMORY;
	}

	s = _t;

	p = strchr(s, '[');
	if (p) {
		*p = '\0';
		options = p + 1;
		if (options[strlen(options)-1] != ']') {
			talloc_free(b);
			return NT_STATUS_INVALID_PARAMETER_MIX;
		}
		options[strlen(options)-1] = 0;
	}

	p = strchr(s, '@');

	if (p && PTR_DIFF(p, s) == 36) { /* 36 is the length of a UUID */
		*p = '\0';

		status = dcerpc_binding_set_string_option(b, "object", s);
		if (!NT_STATUS_IS_OK(status)) {
			talloc_free(b);
			return status;
		}

		s = p + 1;
	}

	p = strchr(s, ':');

	if (p == NULL) {
		b->transport = NCA_UNKNOWN;
	} else if (is_ipaddress_v6(s)) {
		b->transport = NCA_UNKNOWN;
	} else {
		*p = '\0';

		status = dcerpc_binding_set_string_option(b, "transport", s);
		if (!NT_STATUS_IS_OK(status)) {
			talloc_free(b);
			return status;
		}

		s = p + 1;
	}

	if (strlen(s) > 0) {
		status = dcerpc_binding_set_string_option(b, "host", s);
		if (!NT_STATUS_IS_OK(status)) {
			talloc_free(b);
			return status;
		}

		b->target_hostname = talloc_strdup(b, b->host);
		if (b->target_hostname == NULL) {
			talloc_free(b);
			return NT_STATUS_NO_MEMORY;
		}
	}

	for (i=0; options != NULL; i++) {
		const char *name = options;
		const char *value = NULL;

		p = strchr(options, ',');
		if (p != NULL) {
			*p = '\0';
			options = p+1;
		} else {
			options = NULL;
		}

		p = strchr(name, '=');
		if (p != NULL) {
			*p = '\0';
			value = p + 1;
		}

		if (value == NULL) {
			/*
			 * If it's not a key=value pair
			 * it might be a ncacn_option
			 * or if it's the first option
			 * it's the endpoint.
			 */
			const struct ncacn_option *no = NULL;

			value = name;

			no = ncacn_option_by_name(name);
			if (no == NULL) {
				if (i > 0) {
					/*
					 * we don't allow unknown options
					 */
					return NT_STATUS_INVALID_PARAMETER_MIX;
				}

				/*
				 * This is the endpoint
				 */
				name = "endpoint";
				if (strlen(value) == 0) {
					value = NULL;
				}
			}
		}

		status = dcerpc_binding_set_string_option(b, name, value);
		if (!NT_STATUS_IS_OK(status)) {
			talloc_free(b);
			return status;
		}
	}

	talloc_free(_t);
	*b_out = b;
	return NT_STATUS_OK;
}