summaryrefslogtreecommitdiffstats
path: root/src/plugin.c
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-06-06 19:27:14 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-06-06 19:27:14 -0400
commit28ba5b9744b6233d5ad3d6da94d91fcf6ab49317 (patch)
tree9f2d581cd7c99360aac5822ce99781fd28802bfb /src/plugin.c
parentaa0b17ae06f7e774a9990d550ce1fa623d7606db (diff)
downloadslapi-nis-28ba5b9744b6233d5ad3d6da94d91fcf6ab49317.tar.gz
slapi-nis-28ba5b9744b6233d5ad3d6da94d91fcf6ab49317.tar.xz
slapi-nis-28ba5b9744b6233d5ad3d6da94d91fcf6ab49317.zip
- try to read a port number from the configuration entry, if we can
- regardless, try to use the same port number for connected and datagram clients
Diffstat (limited to 'src/plugin.c')
-rw-r--r--src/plugin.c61
1 files changed, 55 insertions, 6 deletions
diff --git a/src/plugin.c b/src/plugin.c
index 061381c..d8155c3 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -63,7 +63,7 @@
static Slapi_PluginDesc
plugin_description = {
.spd_id = "nis-plugin",
- .spd_vendor = "badvocacy.net",
+ .spd_vendor = "redhat.com",
.spd_version = PACKAGE_VERSION,
.spd_description = "NIS Server Plugin",
};
@@ -149,21 +149,42 @@ plugin_shutdown(Slapi_PBlock *pb)
static int
plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
{
- int sockfd = -1, err, i;
+ int port = 0, sockfd = -1, err, i;
struct plugin_state *state = NULL;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
+ Slapi_DN *sdn;
+ Slapi_Entry *e;
+ char *attrs[] = {
+ PLUGIN_CONFIGURATION_MAXDGRAM_ATTR,
+ PLUGIN_CONFIGURATION_MAXVALUE_ATTR,
+ PLUGIN_CONFIGURATION_PORT_ATTR,
+ PLUGIN_CONFIGURATION_SECURENET_ATTR,
+ PLUGIN_CONFIGURATION_TCPWRAPNAME_ATTR,
+ NULL,
+ };
state = malloc(sizeof(*state));
if (state == NULL) {
goto failed;
}
+ memset(state, 0, sizeof(*state));
state->plugin_base = NULL;
state->plugin_desc = &plugin_description;
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);
+ e = NULL;
+ if (state->plugin_base != NULL) {
+ /* Make this conditional. As of this writing this isn't
+ * filled-in yet. */
+ sdn = slapi_sdn_new_dn_byval(state->plugin_base);
+ slapi_search_internal_get_entry(sdn, attrs, &e,
+ state->plugin_identity);
+ slapi_sdn_free(&sdn);
+ sdn = NULL;
+ }
#ifdef HAVE_TCPD_H
state->request_info = malloc(sizeof(*(state->request_info)));
@@ -175,6 +196,9 @@ plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
"error initializing tcp_wrappers for \"%s\"\n",
plugin_description.spd_id);
+ if (e != NULL) {
+ slapi_entry_free(e);
+ }
return -1;
}
#else
@@ -197,8 +221,14 @@ 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;
+ if (e != NULL) {
+ port = slapi_entry_attr_get_int(e,
+ PLUGIN_CONFIGURATION_PORT_ATTR);
+ } else {
+ port = 0;
+ }
for (i = 0; i < 2; i++) {
- int pf, type, one, flags, port, ret;
+ 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
@@ -238,13 +268,26 @@ plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
if ((flags & O_NONBLOCK) == 0) {
fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
}
- /* Bind to a reserved port, don't really care which one. */
+ /* Bind to the server port. */
memset(&sin, 0, sizeof(sin));
memset(&sin6, 0, sizeof(sin6));
sin.sin_family = AF_INET;
sin6.sin6_family = AF_INET6;
- ret = (pf == PF_INET6) ? bindresvport(sockfd, (struct sockaddr_in*) &sin6) :
- bindresvport(sockfd, &sin);
+ if (port == 0) {
+ ret = (pf == PF_INET6) ? bindresvport(sockfd,
+ (struct sockaddr_in*) &sin6) :
+ bindresvport(sockfd,
+ &sin);
+ } else {
+ sin.sin_port = ntohs(port);
+ sin6.sin6_port = ntohs(port);
+ ret = (pf == PF_INET6) ? bind(sockfd,
+ (struct sockaddr*) &sin6,
+ sizeof(sin6)) :
+ bind(sockfd,
+ (struct sockaddr*) &sin,
+ sizeof(sin));
+ }
if (ret != 0) {
slapi_log_error(SLAPI_LOG_PLUGIN,
plugin_description.spd_id,
@@ -285,9 +328,15 @@ plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
slapi_log_error(SLAPI_LOG_PLUGIN,
plugin_description.spd_id,
"set up %d listening sockets\n", state->n_listeners);
+ if (e != NULL) {
+ slapi_entry_free(e);
+ }
*lstate = state;
return 0;
failed:
+ if (e != NULL) {
+ slapi_entry_free(e);
+ }
err = errno;
free(state);
errno = err;