示例#1
0
/*
  open the smb server sockets
*/
static void samba3_smb_task_init(struct task_server *task)
{
	NTSTATUS status;
	const struct model_ops *model_ops;

	model_ops = process_model_startup("standard");

	if (model_ops == NULL) {
		goto failed;
	}

	task_server_set_title(task, "task[samba3_smb]");

	if (lpcfg_interfaces(task->lp_ctx)
	    && lpcfg_bind_interfaces_only(task->lp_ctx)) {
		int num_interfaces;
		int i;
		struct interface *ifaces;

		load_interface_list(task, task->lp_ctx, &ifaces);

		num_interfaces = iface_list_count(ifaces);

		/* We have been given an interfaces line, and been
		   told to only bind to those interfaces. Create a
		   socket per interface and bind to only these.
		*/
		for(i = 0; i < num_interfaces; i++) {
			const char *address = iface_list_n_ip(ifaces, i);
			status = samba3_add_socket(task,
						   task->event_ctx,
						   task->lp_ctx,
						   model_ops, address);
			if (!NT_STATUS_IS_OK(status)) goto failed;
		}
	} else {
		const char **wcard;
		int i;
		wcard = iface_list_wildcard(task, task->lp_ctx);
		if (wcard == NULL) {
			DEBUG(0,("No wildcard addresses available\n"));
			goto failed;
		}
		for (i=0; wcard[i]; i++) {
			status = samba3_add_socket(task,
						   task->event_ctx, task->lp_ctx,
						   model_ops,
						   wcard[i]);
			if (!NT_STATUS_IS_OK(status)) goto failed;
		}
		talloc_free(wcard);
	}

	return;
failed:
	task_server_terminate(task, "Failed to startup samba3 smb task", true);
}
示例#2
0
/*
  startup the cldapd task
*/
static void cldapd_task_init(struct task_server *task)
{
	struct cldapd_server *cldapd;
	NTSTATUS status;
	struct interface *ifaces;
	
	load_interfaces(task, lpcfg_interfaces(task->lp_ctx), &ifaces);

	if (iface_count(ifaces) == 0) {
		task_server_terminate(task, "cldapd: no network interfaces configured", false);
		return;
	}

	switch (lpcfg_server_role(task->lp_ctx)) {
	case ROLE_STANDALONE:
		task_server_terminate(task, "cldap_server: no CLDAP server required in standalone configuration", 
				      false);
		return;
	case ROLE_DOMAIN_MEMBER:
		task_server_terminate(task, "cldap_server: no CLDAP server required in member server configuration",
				      false);
		return;
	case ROLE_DOMAIN_CONTROLLER:
		/* Yes, we want an CLDAP server */
		break;
	}

	task_server_set_title(task, "task[cldapd]");

	cldapd = talloc(task, struct cldapd_server);
	if (cldapd == NULL) {
		task_server_terminate(task, "cldapd: out of memory", true);
		return;
	}

	cldapd->task = task;
	cldapd->samctx = samdb_connect(cldapd, task->event_ctx, task->lp_ctx, system_session(task->lp_ctx), 0);
	if (cldapd->samctx == NULL) {
		task_server_terminate(task, "cldapd failed to open samdb", true);
		return;
	}

	/* start listening on the configured network interfaces */
	status = cldapd_startup_interfaces(cldapd, task->lp_ctx, ifaces);
	if (!NT_STATUS_IS_OK(status)) {
		task_server_terminate(task, "cldapd failed to setup interfaces", true);
		return;
	}

	irpc_add_name(task->msg_ctx, "cldap_server");
}
示例#3
0
文件: interface.c 项目: rti7743/samba
/**
load the list of network interfaces
**/
void load_interface_list(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, struct interface **local_interfaces)
{
    const char **ptr = lpcfg_interfaces(lp_ctx);
    int i;
    struct iface_struct *ifaces;
    int total_probed;
    bool enable_ipv6 = lpcfg_parm_bool(lp_ctx, NULL, "ipv6", "enable", true);

    *local_interfaces = NULL;

    /* probe the kernel for interfaces */
    total_probed = get_interfaces(mem_ctx, &ifaces);

    /* if we don't have a interfaces line then use all interfaces
       except loopback */
    if (!ptr || !*ptr || !**ptr) {
        if (total_probed <= 0) {
            DEBUG(0,("ERROR: Could not determine network interfaces, you must use a interfaces config line\n"));
        }
        for (i=0; i<total_probed; i++) {
            if (!is_loopback_addr((struct sockaddr *)&ifaces[i].ip)) {
                add_interface(mem_ctx, &ifaces[i], local_interfaces, enable_ipv6);
            }
        }
    }

    while (ptr && *ptr) {
        interpret_interface(mem_ctx, *ptr, ifaces, total_probed, local_interfaces, enable_ipv6);
        ptr++;
    }

    if (!*local_interfaces) {
        DEBUG(0,("WARNING: no network interfaces found\n"));
    }
    talloc_free(ifaces);
}
示例#4
0
/*
  startup the wrepl port 42 server sockets
*/
NTSTATUS wreplsrv_setup_sockets(struct wreplsrv_service *service, struct loadparm_context *lp_ctx)
{
	NTSTATUS status;
	struct task_server *task = service->task;
	const struct model_ops *model_ops;
	const char *address;
	uint16_t port = WINS_REPLICATION_PORT;

	/* within the wrepl task we want to be a single process, so
	   ask for the single process model ops and pass these to the
	   stream_setup_socket() call. */
	model_ops = process_model_startup("single");
	if (!model_ops) {
		DEBUG(0,("Can't find 'single' process model_ops"));
		return NT_STATUS_INTERNAL_ERROR;
	}

	if (lpcfg_interfaces(lp_ctx) && lpcfg_bind_interfaces_only(lp_ctx)) {
		int num_interfaces;
		int i;
		struct interface *ifaces;

		load_interface_list(task, lp_ctx, &ifaces);

		num_interfaces = iface_list_count(ifaces);

		/* We have been given an interfaces line, and been 
		   told to only bind to those interfaces. Create a
		   socket per interface and bind to only these.
		*/
		for(i = 0; i < num_interfaces; i++) {
			if (!iface_list_n_is_v4(ifaces, i)) {
				continue;
			}
			address = iface_list_n_ip(ifaces, i);
			status = stream_setup_socket(task, task->event_ctx,
						     task->lp_ctx, model_ops,
						     &wreplsrv_stream_ops,
						     "ipv4", address, &port, 
					              lpcfg_socket_options(task->lp_ctx),
						     service);
			if (!NT_STATUS_IS_OK(status)) {
				DEBUG(0,("stream_setup_socket(address=%s,port=%u) failed - %s\n",
					 address, port, nt_errstr(status)));
				return status;
			}
		}
	} else {
		address = "0.0.0.0";
		status = stream_setup_socket(task, task->event_ctx, task->lp_ctx,
					     model_ops, &wreplsrv_stream_ops,
					     "ipv4", address, &port, lpcfg_socket_options(task->lp_ctx),
					     service);
		if (!NT_STATUS_IS_OK(status)) {
			DEBUG(0,("stream_setup_socket(address=%s,port=%u) failed - %s\n",
				 address, port, nt_errstr(status)));
			return status;
		}
	}

	return NT_STATUS_OK;
}
示例#5
0
/*
  startup the web server task
*/
static void websrv_task_init(struct task_server *task)
{
	NTSTATUS status;
	uint16_t port = lpcfg_web_port(task->lp_ctx);
	const struct model_ops *model_ops;
	struct web_server_data *wdata;

	task_server_set_title(task, "task[websrv]");

	/* run the web server as a single process */
	model_ops = process_model_startup("single");
	if (!model_ops) goto failed;

	/* startup the Python processor - unfortunately we can't do this
	   per connection as that wouldn't allow for session variables */
	wdata = talloc_zero(task, struct web_server_data);
	if (wdata == NULL) goto failed;

	wdata->task = task;
	task->private_data = wdata;

	if (lpcfg_interfaces(task->lp_ctx) && lpcfg_bind_interfaces_only(task->lp_ctx)) {
		int num_interfaces;
		int i;
		struct interface *ifaces;

		load_interface_list(NULL, task->lp_ctx, &ifaces);

		num_interfaces = iface_list_count(ifaces);
		for(i = 0; i < num_interfaces; i++) {
			const char *address = iface_list_n_ip(ifaces, i);
			status = stream_setup_socket(task,
						     task->event_ctx,
						     task->lp_ctx, model_ops,
						     &web_stream_ops, 
						     "ip", address,
						     &port, lpcfg_socket_options(task->lp_ctx),
						     task);
			if (!NT_STATUS_IS_OK(status)) goto failed;
		}

		talloc_free(ifaces);
	} else {
		char **wcard;
		int i;
		wcard = iface_list_wildcard(task);
		if (wcard == NULL) {
			DEBUG(0,("No wildcard addresses available\n"));
			goto failed;
		}
		for (i=0; wcard[i]; i++) {
			status = stream_setup_socket(task, task->event_ctx,
						     task->lp_ctx, model_ops,
						     &web_stream_ops,
						     "ip", wcard[i],
						     &port, lpcfg_socket_options(task->lp_ctx),
						     wdata);
			if (!NT_STATUS_IS_OK(status)) goto failed;
		}
		talloc_free(wcard);
	}

	wdata->tls_params = tls_initialise(wdata, task->lp_ctx);
	if (wdata->tls_params == NULL) goto failed;

	if (!wsgi_initialize(wdata)) goto failed;


	return;

failed:
	task_server_terminate(task, "websrv_task_init: failed to startup web server task", true);
}