summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugin.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/src/plugin.c b/src/plugin.c
index 831b89c..56da368 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -29,7 +29,6 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
-#include <netdb.h>
#include <netinet/in.h>
#include <poll.h>
#include <stdlib.h>
@@ -145,6 +144,32 @@ plugin_shutdown(Slapi_PBlock *pb)
return 0;
}
+/* Read the parameters which we need at initialization-time. */
+static void
+plugin_read_config(Slapi_PBlock *plugin_pb, int *port)
+{
+ Slapi_ComponentId *id;
+ const char *dn, **argv = NULL;
+ int argc = 0, i;
+
+ *port = 0;
+
+ slapi_pblock_get(plugin_pb, SLAPI_PLUGIN_IDENTITY, &id);
+ slapi_pblock_get(plugin_pb, SLAPI_TARGET_DN, &dn);
+ slapi_pblock_get(plugin_pb, SLAPI_PLUGIN_ARGC, &argc);
+ slapi_pblock_get(plugin_pb, SLAPI_PLUGIN_ARGV, &argv);
+ for (i = 0; (i < argc) && (argv != NULL) && (argv[i] != NULL); i++) {
+ switch (i) {
+ case 0:
+ *port = atoi(argv[i]);
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ plugin_description.spd_id,
+ "argument 0 (port) = %d\n", *port);
+ break;
+ }
+ }
+}
+
/* Handle the part of startup that needs to be done before we drop privileges:
* bind to listening ports. */
static int
@@ -166,6 +191,13 @@ plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
state->max_value_size = DEFAULT_MAX_VALUE_SIZE;
state->max_dgram_size = DEFAULT_MAX_DGRAM_SIZE;
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &state->plugin_identity);
+ slapi_pblock_get(pb, SLAPI_TARGET_DN, &state->plugin_base);
+ slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
+ "init: target-dn is %s%s%s\n",
+ state->plugin_base ? "\"" : "",
+ state->plugin_base ? state->plugin_base : "NULL",
+ state->plugin_base ? "\"" : "");
+ plugin_read_config(pb, &port);
#ifdef HAVE_TCPD_H
state->request_info = malloc(sizeof(*(state->request_info)));
@@ -199,7 +231,6 @@ plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
/* We need to bind on privileged ports for both datagram and connected
* listeners, over both IPv4 and IPv6. */
state->n_listeners = 0;
- port = 0;
for (i = 0; i < 2; i++) {
int pf, type, one, flags, ret;
const char *sock_desc;
@@ -246,12 +277,6 @@ plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
memset(&sin6, 0, sizeof(sin6));
sin.sin_family = AF_INET;
sin6.sin6_family = AF_INET6;
- /* Oh, pain. But at this stage we can't read from the
- * directory server's database. */
- serv = getservbyname("ypserv", (i & 1) ? "tcp" : "udp");
- if (serv != NULL) {
- port = ntohs(serv->s_port);
- }
if (port == 0) {
ret = (pf == PF_INET6) ? bindresvport(sockfd,
(struct sockaddr_in*) &sin6) :
@@ -276,7 +301,8 @@ plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
close(sockfd);
continue;
}
- /* Pick out the port number that we got back. */
+ /* Pick out the port number that we got back, in case we used
+ * bindresvport[6]. */
port = (pf == PF_INET6) ? ntohs(sin6.sin6_port) :
ntohs(sin.sin_port);
/* If it's a listening socket, let the kernel know that we're