diff options
Diffstat (limited to 'src/plugin.c')
-rw-r--r-- | src/plugin.c | 61 |
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; |