From 81b0da5fcc1e086c74076df86a8dbd28cf16a625 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Tue, 1 Apr 2008 22:22:01 -0400 Subject: - finish getting the basic NIS server going again --- src/Makefile | 2 +- src/dispatch.c | 16 +++- src/dummymap.c | 24 ++++++ src/map.h | 4 + src/nis.c | 247 +++++++++++++++++++++++++++++++++++++++++++------------- src/plugin.c | 30 ++++--- src/plugin.ldif | 10 +-- src/portmap.c | 37 ++++----- src/portmap.h | 5 +- 9 files changed, 280 insertions(+), 95 deletions(-) (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 9e33b3a..c3abf3b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ -CFLAGS = $(shell pkg-config --cflags nspr nss) -g3 -O0 -Wall -Wimplicit -Wextra -Wno-unused -fPIC -D_REENTRANT +CFLAGS = $(shell pkg-config --cflags nspr nss) -g3 -O1 -Wall -Wimplicit -Wextra -Wno-unused -Wuninitialized -fPIC -D_REENTRANT LDFLAGS = -lnsl -lpthread all:: plugin.so portmap diff --git a/src/dispatch.c b/src/dispatch.c index 728137b..89f69ea 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -192,6 +192,9 @@ dispatch_stream(struct plugin_state *state, int fd) slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "failed to answer new stream request\n"); return; + } else { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "new stream client on %d\n", client); } /* Bundle up enough info for the thread to do its work. */ @@ -213,7 +216,8 @@ dispatch_stream(struct plugin_state *state, int fd) close(client); } slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "started client-specific thread\n"); + "started client-specific thread for client on %d\n", + client); return; } @@ -231,7 +235,7 @@ dispatch_dgram(struct plugin_state *state, int fd) reqsize = recvfrom(fd, dgram, sizeof(dgram), 0, (struct sockaddr *) &client_addr, &client_addrlen); slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "datagram request\n"); + "datagram request (%d bytes)\n", reqsize); /* Handle the request. */ nis_process_request(state, fd, @@ -254,11 +258,19 @@ dispatch_thread(void *p) fds[i].fd = state->listener[i].fd; fds[i].events = POLLIN; } + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "listening for next request\n"); switch (poll(fds, state->n_listeners, -1)) { case -1: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "done waiting\n"); return NULL; break; case 0: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "no request(?)\n"); continue; default: /* Iterate over listening sockets which have work for diff --git a/src/dummymap.c b/src/dummymap.c index daed8e8..07e6ef4 100644 --- a/src/dummymap.c +++ b/src/dummymap.c @@ -79,9 +79,33 @@ map_supports_domain(struct plugin_state *state, break; } } + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "map_supports_domain \"%s\": %s\n", domain, + *supported ? "YES" : "NO"); return TRUE; } +bool_t +map_supports_map(struct plugin_state *state, + const char *domain, const char *map, bool_t *supported) +{ + int i, j; + *supported = FALSE; + for (i = 0; domains[i].domain != NULL; i++) { + if (strcmp(domains[i].domain, domain) == 0) { + break; + } + } + if (domains[i].domain != NULL) { + for (j = 0; domains[i].maps[j].map != NULL; j++) { + if (strcmp(domains[i].maps[j].map, map) == 0) { + *supported = TRUE; + break; + } + } + } + return TRUE; +} bool_t map_order(struct plugin_state *state, diff --git a/src/map.h b/src/map.h index 578e886..dc42c42 100644 --- a/src/map.h +++ b/src/map.h @@ -2,6 +2,10 @@ struct plugin_state; bool_t map_supports_domain(struct plugin_state *state, const char *domain, bool_t *supported); +bool_t map_supports_map(struct plugin_state *state, + const char *domain, + const char *map, + bool_t *supported); bool_t map_match(struct plugin_state *state, const char *domain, const char *map, unsigned int key_len, char *key, diff --git a/src/nis.c b/src/nis.c index e487415..0d74f13 100644 --- a/src/nis.c +++ b/src/nis.c @@ -19,8 +19,41 @@ #include "nis.h" #include "plugin.h" -#define DUMMY_KEY "leeroy" -#define DUMMY_VAL "jimbo:*K*:1234:5678:Leeroy Jenkins:/home/leeroy:/bin/bash" +static ssize_t +nis_write_with_retry(struct plugin_state *state, + int fd, const void *buffer, ssize_t length) +{ + ssize_t sent, i; + sent = 0; + while ((sent != -1) && (sent != length)) { + i = write(fd, ((unsigned char *)buffer) + sent, length - sent); + switch (i) { + case 0: + sent = -1; + break; + case -1: + switch (errno) { + case EAGAIN: + continue; + break; + default: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "Got error %s sending " + "%d bytes (at %d) to %d.\n", + strerror(errno), length, sent, + fd); + sent = -1; + break; + } + break; + default: + sent += i; + break; + } + } + return sent; +} /* Send a reply which _could_ be sent over a datagram. */ static void @@ -30,8 +63,7 @@ nis_reply_fragment(struct plugin_state *state, int client, bool_t first_fragment, bool_t last_fragment) { uint32_t len; - struct iovec iov[2]; - ssize_t i; + ssize_t i, sent; if (client_addr != NULL) { /* It's a datagram socket, so there's nothing to do but send * the data by itself. */ @@ -49,19 +81,19 @@ nis_reply_fragment(struct plugin_state *state, int client, /* Calculate the fragment length bytes. */ len = htonl(xdr_getpos(reply_xdrs) | (last_fragment ? 0x80000000 : 0)); - slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "Stream reply (4+%d bytes)\n", - xdr_getpos(reply_xdrs)); /* Send the data to the client. */ - iov[0].iov_base = &len; - iov[0].iov_len = 4; - iov[1].iov_base = reply_buf; - iov[1].iov_len = xdr_getpos(reply_xdrs); - i = writev(client, iov, 2); - if (i != (4 + xdr_getpos(reply_xdrs))) { + if ((nis_write_with_retry(state, client, &len, 4) == 4) && + (nis_write_with_retry(state, client, reply_buf, + xdr_getpos(reply_xdrs)) == + xdr_getpos(reply_xdrs))) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "Error sending stream reply!\n"); + "Stream reply (4+%d bytes) sent.\n", + xdr_getpos(reply_xdrs)); + } else { + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "Stream reply (4+%d bytes) failed!\n"); } } } @@ -102,6 +134,9 @@ nis_domain(struct plugin_state *state, domain, *reply_bool ? "TRUE" : "FALSE"); } } else { + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "argument parsing error\n"); /* XXX */ } } @@ -150,6 +185,8 @@ nis_first(struct plugin_state *state, struct ypresp_key_val *reply_key_val) { struct ypreq_nokey req_nokey; + bool_t map_supported; + memset(&req_nokey, 0, sizeof(req_nokey)); memset(reply_key_val, 0, sizeof(*reply_key_val)); if (xdr_ypreq_nokey(request_xdrs, &req_nokey)) { @@ -166,7 +203,11 @@ nis_first(struct plugin_state *state, req_nokey.map, reply_key_val->status); } else { - reply_key_val->status = YP_NOKEY; + map_supported = FALSE; + map_supports_map(state, req_nokey.domain, req_nokey.map, + &map_supported); + reply_key_val->status = map_supported ? YP_NOKEY : + YP_NOMAP; } nis_reply(state, client, client_addr, client_addrlen, reply, reply_xdrs, reply_buf); @@ -321,58 +362,100 @@ nis_all(struct plugin_state *state, int client, struct sockaddr *client_addr, socklen_t client_addrlen, XDR *request_xdrs, struct rpc_msg *reply, XDR *reply_xdrs, char *reply_buf, - bool_t *reply_more) + struct ypresp_all *reply_all) { - char domain[YPMAXDOMAIN + 1], *p; - int i; - keydat_t keydat; - bool_t more; struct ypreq_nokey req_nokey; - struct ypresp_key_val reply_key_val; + keydat_t *reply_key; + valdat_t *reply_val; + bool_t supported; - memset(&reply_key_val, 0, sizeof(reply_key_val)); - *reply_more = FALSE; memset(&req_nokey, 0, sizeof(req_nokey)); + reply_key = &reply_all->ypresp_all_u.val.keydat; + reply_val = &reply_all->ypresp_all_u.val.valdat; if (xdr_ypreq_nokey(request_xdrs, &req_nokey)) { - if (map_first(state, req_nokey.domain, req_nokey.map, - &reply_key_val.keydat.keydat_len, - &reply_key_val.keydat.keydat_val, - &reply_key_val.valdat.valdat_len, - &reply_key_val.valdat.valdat_val)) { - *reply_more = TRUE; + if (!map_supports_map(state, req_nokey.domain, req_nokey.map, + &supported) || + !supported) { + /* No entries? No such map final status. */ + reply_all->more = TRUE; + reply_all->ypresp_all_u.val.status = YP_NOMAP; + reply_key->keydat_len = 0; + reply_val->valdat_len = 0; nis_reply_fragment(state, client, client_addr, client_addrlen, reply, reply_xdrs, reply_buf, TRUE, FALSE); - slapi_log_error(SLAPI_LOG_PLUGIN, - state->plugin_desc->spd_id, - "all(%s/%s) -> %d\n", - req_nokey.domain, - req_nokey.map, - *reply_more); + /* End of data. */ + reply_all->more = FALSE; + xdr_setpos(reply_xdrs, 0); + xdr_ypresp_all(reply_xdrs, reply_all); + nis_reply_fragment(state, client, + client_addr, client_addrlen, + reply, reply_xdrs, reply_buf, + FALSE, TRUE); + } else { + bool_t first; + reply_all->more = TRUE; + reply_all->ypresp_all_u.val.status = YP_TRUE; + reply_all->more = map_first(state, + req_nokey.domain, + req_nokey.map, + &reply_key->keydat_len, + &reply_key->keydat_val, + &reply_val->valdat_len, + &reply_val->valdat_val); + first = TRUE; do { - xdr_setpos(reply_xdrs, 0); - xdr_ypresp_key_val(reply_xdrs, &reply_key_val); - keydat = reply_key_val.keydat; - more = map_next(state, - req_nokey.domain, req_nokey.map, - keydat.keydat_len, - keydat.keydat_val, - &reply_key_val.keydat.keydat_len, - &reply_key_val.keydat.keydat_val, - &reply_key_val.valdat.valdat_len, - &reply_key_val.valdat.valdat_val); - xdr_bool(reply_xdrs, &more); + /* Send back a result. If it's the first + * entry, also send back the reply header. */ + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "all(%s/%s) -> (%.*s),%d\n", + req_nokey.domain, + req_nokey.map, + reply_key->keydat_len, + reply_key->keydat_val, + reply_all->more); nis_reply_fragment(state, client, client_addr, client_addrlen, reply, reply_xdrs, reply_buf, - FALSE, !more); - } while(more); - } else { - *reply_more = FALSE; - nis_reply(state, client, - client_addr, client_addrlen, - reply, reply_xdrs, reply_buf); + first, FALSE); + first = FALSE; + /* Find the next entry. */ + reply_all->more = map_next(state, + req_nokey.domain, + req_nokey.map, + reply_key->keydat_len, + reply_key->keydat_val, + &reply_key->keydat_len, + &reply_key->keydat_val, + &reply_val->valdat_len, + &reply_val->valdat_val); + /* If we got an entry, encode it. */ + if (reply_all->more) { + xdr_setpos(reply_xdrs, 0); + xdr_ypresp_all(reply_xdrs, reply_all); + } + } while (reply_all->more); + /* Send the end-of-map marker. */ + reply_all->ypresp_all_u.val.status = YP_NOMORE; + reply_key->keydat_len = 0; + reply_val->valdat_len = 0; + xdr_setpos(reply_xdrs, 0); + reply_all->more = TRUE; + xdr_ypresp_all(reply_xdrs, reply_all); + /* End of data. */ + reply_all->more = FALSE; + xdr_ypresp_all(reply_xdrs, reply_all); + /* Bundle those two chunks into one reply. */ + nis_reply_fragment(state, client, + client_addr, client_addrlen, + reply, reply_xdrs, reply_buf, + FALSE, TRUE); + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "all(%s/%s) done\n", + req_nokey.domain, req_nokey.map); } } else { /* XXX */ @@ -394,6 +477,7 @@ nis_process_request(struct plugin_state *state, int client, int superuser, send_reply, auth_flavor, auth_len; struct ypresp_val reply_val; struct ypresp_key_val reply_key_val; + struct ypresp_all reply_all; struct ypresp_master reply_master; struct ypresp_order reply_order; struct ypresp_maplist reply_maplist; @@ -448,6 +532,12 @@ nis_process_request(struct plugin_state *state, int client, "validated auth_sys creds\n"); superuser = 0; break; + case AUTH_NONE: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "validated \"none\" creds\n"); + superuser = 0; + break; default: slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, @@ -478,6 +568,8 @@ nis_process_request(struct plugin_state *state, int client, auth_destroy(reply_auth); auth_len = xdr_getpos(&auth_xdrs); xdr_destroy(&auth_xdrs); + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "built reply authenticator\n"); /* Fill out the common RPC reply fields. */ reply.rm_xid = request.rm_xid; @@ -491,6 +583,8 @@ nis_process_request(struct plugin_state *state, int client, reply.rm_reply.rp_stat = MSG_DENIED; reply.rm_reply.rp_rjct.rj_stat = RPC_MISMATCH; xdr_replymsg(&reply_xdrs, &reply); + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "program request mismatch\n"); goto send_reply; } @@ -510,10 +604,17 @@ nis_process_request(struct plugin_state *state, int client, reply.rm_reply.rp_rjct.rj_stat = RPC_MISMATCH; break; case YPPROC_NULL: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "yp_null()\n"); /* Do nothing. The default successful reply is fine. */ break; case YPPROC_DOMAIN: case YPPROC_DOMAIN_NONACK: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + request.rm_call.cb_proc == YPPROC_DOMAIN ? + "yp_domain()\n" : "yp_domainnonack()\n"); /* Change the reply data to be a boolean. */ memset(&reply_bool, 0, sizeof(reply_bool)); accepted->ar_results.where = (caddr_t) &reply_bool; @@ -526,6 +627,9 @@ nis_process_request(struct plugin_state *state, int client, goto sent_reply; break; case YPPROC_MATCH: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "yp_match()\n"); /* Change the reply data to be a resp_val. */ memset(&reply_val, 0, sizeof(reply_val)); accepted->ar_results.where = (caddr_t) &reply_val; @@ -537,6 +641,9 @@ nis_process_request(struct plugin_state *state, int client, goto sent_reply; break; case YPPROC_FIRST: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "yp_first()\n"); /* Change the reply data to be a resp_key_val. */ memset(&reply_key_val, 0, sizeof(reply_key_val)); accepted->ar_results.where = (caddr_t) &reply_key_val; @@ -548,6 +655,9 @@ nis_process_request(struct plugin_state *state, int client, goto sent_reply; break; case YPPROC_NEXT: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "yp_next()\n"); /* Change the reply data to be a resp_key_val. */ memset(&reply_key_val, 0, sizeof(reply_key_val)); accepted->ar_results.where = (caddr_t) &reply_key_val; @@ -559,23 +669,35 @@ nis_process_request(struct plugin_state *state, int client, goto sent_reply; break; case YPPROC_XFR: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "yp_xfr()\n"); /* Do nothing. The default successful reply is fine. */ break; case YPPROC_CLEAR: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "yp_clear()\n"); /* Do nothing. The default successful reply is fine. */ break; case YPPROC_ALL: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "yp_all()\n"); /* Set the result type to a boolean. */ - memset(&reply_bool, 0, sizeof(reply_bool)); - accepted->ar_results.where = (caddr_t) &reply_bool; - accepted->ar_results.proc = (xdrproc_t) &xdr_bool; + memset(&reply_all, 0, sizeof(reply_all)); + accepted->ar_results.where = (caddr_t) &reply_all; + accepted->ar_results.proc = (xdrproc_t) &xdr_ypresp_all; /* Call the real function. */ nis_all(state, client, client_addr, client_addrlen, &request_xdrs, - &reply, &reply_xdrs, reply_buf, &reply_bool); + &reply, &reply_xdrs, reply_buf, &reply_all); goto sent_reply; break; case YPPROC_MASTER: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "yp_master()\n"); /* Change reply type to be a resp_master. */ memset(&reply_master, 0, sizeof(reply_master)); accepted->ar_results.where = (caddr_t) &reply_master; @@ -587,6 +709,9 @@ nis_process_request(struct plugin_state *state, int client, goto sent_reply; break; case YPPROC_ORDER: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "yp_order()\n"); /* Change reply type to be a resp_order. */ memset(&reply_order, 0, sizeof(reply_order)); accepted->ar_results.where = (caddr_t) &reply_order; @@ -598,6 +723,9 @@ nis_process_request(struct plugin_state *state, int client, goto sent_reply; break; case YPPROC_MAPLIST: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "yp_maplist()\n"); /* Change reply type to be a resp_maplist. */ memset(&reply_maplist, 0, sizeof(reply_maplist)); accepted->ar_results.where = (caddr_t) &reply_maplist; @@ -609,6 +737,9 @@ nis_process_request(struct plugin_state *state, int client, goto sent_reply; break; case YPPROC_NEWXFR: + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "yp_newxfr()\n"); reply.rm_reply.rp_stat = MSG_DENIED; reply.rm_reply.rp_rjct.rj_stat = RPC_MISMATCH; break; diff --git a/src/plugin.c b/src/plugin.c index ae57e5c..6315b68 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -48,7 +48,8 @@ plugin_startup(Slapi_PBlock *pb) const char *pname; int i, protocol; slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); - slapi_log_error(SLAPI_LOG_PLUGIN, "plugin_start", "plugin starting\n"); + slapi_log_error(SLAPI_LOG_PLUGIN, plugin_description.spd_id, + "plugin starting\n"); /* Register the listener sockets with the portmapper. */ if (state->pmap_client_socket != -1) { for (i = 0; i < state->n_listeners; i++) { @@ -69,7 +70,8 @@ plugin_startup(Slapi_PBlock *pb) if (protocol == IPPROTO_IP) { continue; } - if (!portmap_register(state->pmap_client_socket, + if (!portmap_register(plugin_description.spd_id, + state->pmap_client_socket, YPPROG, YPVERS, protocol, state->listener[i].port)) { slapi_log_error(SLAPI_LOG_PLUGIN, @@ -100,7 +102,8 @@ plugin_shutdown(Slapi_PBlock *pb) slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); if (state->pmap_client_socket != -1) { /* Clear our registration with the portmapper. */ - portmap_unregister(state->pmap_client_socket, YPPROG, YPVERS); + portmap_unregister(plugin_description.spd_id, + state->pmap_client_socket, YPPROG, YPVERS); } return 0; } @@ -126,6 +129,19 @@ plugin_state_init(struct plugin_state **lstate) } state->arena = arena; + /* Create a socket for use in communicating with the portmapper. */ + sockfd = socket(PF_INET, SOCK_DGRAM, 0); + if (sockfd == -1) { + goto failed; + } + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + if (bindresvport(sockfd, &sin) != 0) { + close(sockfd); + goto failed; + } + state->pmap_client_socket = sockfd; + /* We need to bind on privileged ports for both datagram and connected * listeners, over both IPv4 and IPv6. */ state->n_listeners = 0; @@ -158,11 +174,12 @@ plugin_state_init(struct plugin_state **lstate) continue; } /* Mark the socket as reusable. */ + one = 1; if (setsockopt(sockfd, IPPROTO_IP, SO_REUSEADDR, &one, sizeof(one)) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, plugin_description.spd_id, - "error marking %s socket for reuse, ", + "error marking %s socket for reuse, " "continuing\n", sock_desc); } /* Bind to a reserved port. */ @@ -197,11 +214,6 @@ plugin_state_init(struct plugin_state **lstate) continue; } } - /* Save the first socket for reuse as the portmap client - * socket. */ - if (i == 0) { - state->pmap_client_socket = sockfd; - } /* Save the other info. */ state->listener[state->n_listeners].fd = sockfd; state->listener[state->n_listeners].port = port; diff --git a/src/plugin.ldif b/src/plugin.ldif index 09931dd..cd91340 100644 --- a/src/plugin.ldif +++ b/src/plugin.ldif @@ -1,14 +1,14 @@ -dn: cn=My Plugin, cn=plugins, cn=config +dn: cn=NIS Server, cn=plugins, cn=config objectclass: top objectclass: nsSlapdPlugin objectclass: extensibleObject -cn: My Plugin +cn: NIS Server nsslapd-pluginpath: /usr/src/local/sn/src/plugin.so nsslapd-plugininitfunc: nis_plugin_init nsslapd-plugintype: object nsslapd-pluginenabled: on -nsslapd-pluginid: my-plugin +nsslapd-pluginid: nis-plugin nsslapd-version: 0.0 -nsslapd-pluginvendor: hamdingers.org -nsslapd-plugindescription: sample plugin +nsslapd-pluginvendor: badvocacy.net +nsslapd-plugindescription: NIS Server Plugin diff --git a/src/portmap.c b/src/portmap.c index ebb85de..44c0abe 100644 --- a/src/portmap.c +++ b/src/portmap.c @@ -39,19 +39,19 @@ main(int argc, char **argv) printf("error binding to reserved port\n"); } setreuid(2510, 2510); - portmap_unregister(s, YPPROG, YPVERS); - portmap_register(s, YPPROG, YPVERS, IPPROTO_UDP, + portmap_unregister("portmap", s, YPPROG, YPVERS); + portmap_register("portmap", s, YPPROG, YPVERS, IPPROTO_UDP, ntohs(sin.sin_port)); return 0; } #endif static bool_t -portmap_register_work(int resv_sock, +portmap_register_work(const char *module, int resv_sock, int program, int version, int protocol, int port, int proc) { - char portmap_buf[4000], auth_buf[4000], reply_buf[8000]; + char portmap_buf[4000], auth_buf[4000], reply_buf[8000], *log_id; int portmap_length, reply_length; AUTH *auth; XDR portmap_xdrs, auth_xdrs; @@ -68,6 +68,7 @@ portmap_register_work(int resv_sock, int i; static u_long xid; + log_id = (char *) module; memset(&addr, 0, sizeof(addr)); addr.sa_family = AF_UNSPEC; @@ -117,7 +118,7 @@ portmap_register_work(int resv_sock, * immediately retry. */ if (send(resv_sock, &portmap_buf, portmap_length, 0) != portmap_length) { - slapi_log_error(SLAPI_LOG_PLUGIN, "XXX", + slapi_log_error(SLAPI_LOG_PLUGIN, log_id, "error sending request to portmap\n"); continue; } @@ -159,7 +160,7 @@ portmap_register_work(int resv_sock, /* Disconnect from the portmapper, but keep our socket around. */ connect(resv_sock, &addr, sizeof(addr)); if (i == 32) { - slapi_log_error(SLAPI_LOG_PLUGIN, "XXX", + slapi_log_error(SLAPI_LOG_PLUGIN, log_id, "timeout registering with portmap service\n"); return FALSE; } @@ -167,7 +168,7 @@ portmap_register_work(int resv_sock, /* Check that the portmapper didn't just reject the request out of * hand. */ if (msg.rm_reply.rp_stat != MSG_ACCEPTED) { - slapi_log_error(SLAPI_LOG_PLUGIN, "XXX", + slapi_log_error(SLAPI_LOG_PLUGIN, log_id, "portmap request not accepted\n"); switch (msg.rm_reply.rp_rjct.rj_stat) { const char *auth_status; @@ -199,13 +200,13 @@ portmap_register_work(int resv_sock, auth_status = "unknown error"; break; } - slapi_log_error(SLAPI_LOG_PLUGIN, "XXX", + slapi_log_error(SLAPI_LOG_PLUGIN, log_id, "portmap request rejected: " "authentication failed: %s\n", auth_status); break; case RPC_MISMATCH: - slapi_log_error(SLAPI_LOG_PLUGIN, "XXX", + slapi_log_error(SLAPI_LOG_PLUGIN, log_id, "portmap request rejected: " "RPC mismatch\n"); break; @@ -217,17 +218,17 @@ portmap_register_work(int resv_sock, /* Validate the portmapper's credentials. */ auth = authunix_create_default(); if (auth_validate(auth, &msg.rm_reply.rp_acpt.ar_verf)) { - slapi_log_error(SLAPI_LOG_PLUGIN, "XXX", + slapi_log_error(SLAPI_LOG_PLUGIN, log_id, "portmap reply authenticated\n"); } else { - slapi_log_error(SLAPI_LOG_PLUGIN, "XXX", + slapi_log_error(SLAPI_LOG_PLUGIN, log_id, "portmap reply failed authentication\n"); } auth_destroy(auth); /* Check if we the portmapper gave us a reply argument. */ if (msg.rm_reply.rp_acpt.ar_stat != SUCCESS) { - slapi_log_error(SLAPI_LOG_PLUGIN, "XXX", + slapi_log_error(SLAPI_LOG_PLUGIN, log_id, "portmap request not processed\n"); xdr_destroy(&portmap_xdrs); return FALSE; @@ -235,10 +236,10 @@ portmap_register_work(int resv_sock, /* Check what happened. */ if (ret) { - slapi_log_error(SLAPI_LOG_PLUGIN, "XXX", + slapi_log_error(SLAPI_LOG_PLUGIN, log_id, "portmap request succeeded\n"); } else { - slapi_log_error(SLAPI_LOG_PLUGIN, "XXX", + slapi_log_error(SLAPI_LOG_PLUGIN, log_id, "portmap response did not include a reply\n"); } @@ -248,16 +249,16 @@ portmap_register_work(int resv_sock, } bool_t -portmap_register(int resv_sock, +portmap_register(const char *log_id, int resv_sock, int program, int version, int protocol, int port) { - return portmap_register_work(resv_sock, program, version, + return portmap_register_work(log_id, resv_sock, program, version, protocol, port, PMAPPROC_SET); } bool_t -portmap_unregister(int resv_sock, int program, int version) +portmap_unregister(const char *log_id, int resv_sock, int program, int version) { - return portmap_register_work(resv_sock, program, version, + return portmap_register_work(log_id, resv_sock, program, version, 0, 0, PMAPPROC_UNSET); } diff --git a/src/portmap.h b/src/portmap.h index 9161095..1601b7b 100644 --- a/src/portmap.h +++ b/src/portmap.h @@ -3,8 +3,9 @@ #include -bool_t portmap_register(int resv_sock, +bool_t portmap_register(const char *log_id, int resv_sock, int program, int version, int protocol, int port); -bool_t portmap_unregister(int resv_sock, int program, int version); +bool_t portmap_unregister(const char *log_id, + int resv_sock, int program, int version); #endif -- cgit