summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-07-03 13:46:20 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-07-03 13:46:20 -0400
commitd0bd372e6602d68a948521950a52650619f5d1c6 (patch)
tree5d6e95ec48305a03cd13db0f6e1508f7e23d2669 /src
parenta1da2533b6bc0828ff49d459c0ba316a159f6497 (diff)
downloadslapi-nis-d0bd372e6602d68a948521950a52650619f5d1c6.tar.gz
slapi-nis-d0bd372e6602d68a948521950a52650619f5d1c6.tar.xz
slapi-nis-d0bd372e6602d68a948521950a52650619f5d1c6.zip
- remove some bogus logic that's left over from when we tried to use a
listening socket to talk to the portmapper
Diffstat (limited to 'src')
-rw-r--r--src/plug-nis.c52
1 files changed, 23 insertions, 29 deletions
diff --git a/src/plug-nis.c b/src/plug-nis.c
index 3640462..514f63f 100644
--- a/src/plug-nis.c
+++ b/src/plug-nis.c
@@ -69,7 +69,8 @@ plugin_description = {
.spd_description = "NIS Server Plugin",
};
-/* Start the plugin's work thread. */
+/* Populate the map cache, register with the local portmapper, and then start
+ * the plugin's work thread to answer requests using the cache. */
static int
plugin_startup(Slapi_PBlock *pb)
{
@@ -80,13 +81,21 @@ plugin_startup(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_TARGET_DN, &state->plugin_base);
/* Populate the maps and data. */
backend_startup(state);
+ /* Start a new listening thread to handle incoming traffic. */
+ state->tid = wrap_start_thread(&dispatch_thread, state);
+ if (state->tid == NULL) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ plugin_description.spd_id,
+ "error starting listener thread\n");
+ return -1;
+ }
/* Register the listener sockets with the portmapper. */
if (state->pmap_client_socket != -1) {
- /* kick off any other NIS servers */
+ /* Kick off any other NIS servers on the local box. */
portmap_unregister(plugin_description.spd_id,
state->pmap_client_socket,
YPPROG, YPVERS);
- /* register our ports */
+ /* Register our listening ports. */
for (i = 0; i < state->n_listeners; i++) {
switch (state->listener[i].type) {
case SOCK_DGRAM:
@@ -116,36 +125,29 @@ plugin_startup(Slapi_PBlock *pb)
}
}
}
- /* Start a new listening thread to handle incoming traffic. */
- state->tid = wrap_start_thread(&dispatch_thread, state);
- if (state->tid == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- plugin_description.spd_id,
- "error starting listener thread\n");
- return -1;
- }
slapi_log_error(SLAPI_LOG_PLUGIN, plugin_description.spd_id,
"plugin startup completed\n");
return 0;
}
-/* Stop the plugin's work thread. */
+/* Unregister with the local portmapper and stop the plugin's work thread. */
static int
plugin_shutdown(Slapi_PBlock *pb)
{
struct plugin_state *state;
slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state);
- wrap_stop_thread(state->tid);
if (state->pmap_client_socket != -1) {
/* Clear our registration with the portmapper. */
portmap_unregister(plugin_description.spd_id,
state->pmap_client_socket, YPPROG, YPVERS);
}
+ wrap_stop_thread(state->tid);
free(state);
return 0;
}
-/* Read the parameters which we need at initialization-time. */
+/* Read the plugin configuration parameters which we need to know at plugin
+ * initialization time, before the server drops privileges. */
static void
plugin_read_config(Slapi_PBlock *plugin_pb, int *port)
{
@@ -172,7 +174,7 @@ plugin_read_config(Slapi_PBlock *plugin_pb, int *port)
}
/* Handle the part of startup that needs to be done before we drop privileges:
- * bind to listening ports. */
+ * bind to listening ports and one more for talking to the local portmapper. */
static int
plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
{
@@ -234,16 +236,6 @@ plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
for (i = 0; i < 2; i++) {
int pf, type, one, flags, ret;
const char *sock_desc;
- /* Before we do anything else, on our second trip through, make
- * sure that the first socket was created, because we'll need
- * it for communicating with the portmapper. */
- if ((i > 0) && (state->n_listeners == 0)) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- plugin_description.spd_id,
- "no socket available to use for "
- "communicating with portmapper\n");
- continue;
- }
/* Figure out what kind of socket we need, and a textual
* term to use in log messages. */
pf = (i & 2) ? PF_INET6 : PF_INET;
@@ -272,7 +264,8 @@ plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
if ((flags & O_NONBLOCK) == 0) {
fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
}
- /* Bind to the server port. */
+ /* Bind to the server port, if one was specified, otherwise let
+ * libc try to find an unused one for us. */
memset(&sin, 0, sizeof(sin));
memset(&sin6, 0, sizeof(sin6));
sin.sin_family = AF_INET;
@@ -301,7 +294,7 @@ plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
close(sockfd);
continue;
}
- /* Pick out the port number that we got back, in case we used
+ /* Read the port number that we ended up using, in case we used
* bindresvport[6]. */
port = (pf == PF_INET6) ? ntohs(sin6.sin6_port) :
ntohs(sin.sin_port);
@@ -346,7 +339,7 @@ int
nis_plugin_init(Slapi_PBlock *pb)
{
struct plugin_state *state = NULL;
- /* Allocate a memory pool and start listening for connections. */
+ /* Allocate the module-global data and set up listening sockets. */
if (plugin_state_init(pb, &state) == -1) {
slapi_log_error(SLAPI_LOG_PLUGIN, plugin_description.spd_id,
"error setting up plugin\n");
@@ -358,7 +351,8 @@ nis_plugin_init(Slapi_PBlock *pb)
slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN, &plugin_startup);
slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN, &plugin_shutdown);
slapi_pblock_set(pb, SLAPI_PLUGIN_PRIVATE, state);
- /* Let the backend do its registration. */
+ /* Let the map cache initialize itself and let the backend do its
+ * registration. */
map_init(pb, state);
backend_init(pb, state);
slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,