X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fstatd%2Frmtcall.c;h=5700fc73c45a64f32f5cbeea724dcfbfd5d494a5;hp=82405290f3356fe5b1009635d112dc7aaa42d4c0;hb=9ccfe0fa5a43dfc4453b09e328565a6c8f999fe4;hpb=7bc7c11507c853b8835e9f2ad758b8958c5607af diff --git a/utils/statd/rmtcall.c b/utils/statd/rmtcall.c index 8240529..5700fc7 100644 --- a/utils/statd/rmtcall.c +++ b/utils/statd/rmtcall.c @@ -43,7 +43,6 @@ #include "sm_inter.h" #include "statd.h" #include "notlist.h" -#include "log.h" #include "ha-callout.h" #if SIZEOF_SOCKLEN_T - 0 == 0 @@ -56,7 +55,15 @@ static unsigned long xid = 0; /* RPC XID counter */ static int sockfd = -1; /* notify socket */ /* - * Initialize callback socket + * Initialize socket used to notify lockd of peer reboots. + * + * Returns the file descriptor of the new socket if successful; + * otherwise returns -1 and logs an error. + * + * Lockd rejects such requests if the source port is not privileged. + * statd_get_socket() must be invoked while statd still holds root + * privileges in order for the socket to acquire a privileged source + * port. */ int statd_get_socket(void) @@ -73,7 +80,7 @@ statd_get_socket(void) if (sockfd >= 0) close(sockfd); if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { - note(N_CRIT, "%s: Can't create socket: %m", __func__); + xlog(L_ERROR, "%s: Can't create socket: %m", __func__); return -1; } @@ -83,7 +90,7 @@ statd_get_socket(void) sin.sin_addr.s_addr = INADDR_ANY; if (bindresvport(sockfd, &sin) < 0) { - dprintf(N_WARNING, "%s: can't bind to reserved port", + xlog(D_GENERAL, "%s: can't bind to reserved port", __func__); break; } @@ -97,7 +104,7 @@ statd_get_socket(void) } static unsigned long -xmit_call(int sockfd, struct sockaddr_in *sin, +xmit_call(struct sockaddr_in *sin, u_int32_t prog, u_int32_t vers, u_int32_t proc, xdrproc_t func, void *obj) /* __u32 prog, __u32 vers, __u32 proc, xdrproc_t func, void *obj) */ @@ -142,7 +149,7 @@ xmit_call(int sockfd, struct sockaddr_in *sin, /* Encode the RPC header part and payload */ if (!xdr_callmsg(xdrs, &mesg) || !func(xdrs, obj)) { - dprintf(N_WARNING, "%s: can't encode RPC message!", __func__); + xlog(D_GENERAL, "%s: can't encode RPC message!", __func__); xdr_destroy(xdrs); return 0; } @@ -152,9 +159,9 @@ xmit_call(int sockfd, struct sockaddr_in *sin, if ((err = sendto(sockfd, msgbuf, msglen, 0, (struct sockaddr *) sin, sizeof(*sin))) < 0) { - dprintf(N_WARNING, "%s: sendto failed: %m", __func__); + xlog_warn("%s: sendto failed: %m", __func__); } else if (err != msglen) { - dprintf(N_WARNING, "%s: short write: %m", __func__); + xlog_warn("%s: short write: %m", __func__); } xdr_destroy(xdrs); @@ -163,7 +170,7 @@ xmit_call(int sockfd, struct sockaddr_in *sin, } static notify_list * -recv_rply(int sockfd, struct sockaddr_in *sin, u_long *portp) +recv_rply(struct sockaddr_in *sin, u_long *portp) { unsigned int msgbuf[MAXMSGSIZE], msglen; struct rpc_msg mesg; @@ -174,7 +181,7 @@ recv_rply(int sockfd, struct sockaddr_in *sin, u_long *portp) /* Receive message */ if ((msglen = recvfrom(sockfd, msgbuf, sizeof(msgbuf), 0, (struct sockaddr *) sin, &alen)) < 0) { - dprintf(N_WARNING, "%s: recvfrom failed: %m", __func__); + xlog_warn("%s: recvfrom failed: %m", __func__); return NULL; } @@ -186,19 +193,19 @@ recv_rply(int sockfd, struct sockaddr_in *sin, u_long *portp) mesg.rm_reply.rp_acpt.ar_results.proc = (xdrproc_t) xdr_void; if (!xdr_replymsg(xdrs, &mesg)) { - note(N_WARNING, "%s: can't decode RPC message!", __func__); + xlog_warn("%s: can't decode RPC message!", __func__); goto done; } if (mesg.rm_reply.rp_stat != 0) { - note(N_WARNING, "%s: [%s] RPC status %d", + xlog_warn("%s: [%s] RPC status %d", __func__, inet_ntoa(sin->sin_addr), mesg.rm_reply.rp_stat); goto done; } if (mesg.rm_reply.rp_acpt.ar_stat != 0) { - note(N_WARNING, "%s: [%s] RPC status %d", + xlog_warn("%s: [%s] RPC status %d", __func__, inet_ntoa(sin->sin_addr), mesg.rm_reply.rp_acpt.ar_stat); @@ -216,14 +223,13 @@ recv_rply(int sockfd, struct sockaddr_in *sin, u_long *portp) strncpy (addr, inet_ntoa(lp->addr), sizeof (addr) - 1); addr [sizeof (addr) - 1] = '\0'; - dprintf(N_WARNING, "%s: address mismatch: " + xlog_warn("%s: address mismatch: " "expected %s, got %s", __func__, addr, inet_ntoa(sin->sin_addr)); } if (lp->port == 0) { if (!xdr_u_long(xdrs, portp)) { - note(N_WARNING, - "%s: [%s] can't decode reply body!", + xlog_warn("%s: [%s] can't decode reply body!", __func__, inet_ntoa(sin->sin_addr)); lp = NULL; @@ -242,7 +248,7 @@ done: * Notify operation for a single list entry */ static int -process_entry(int sockfd, notify_list *lp) +process_entry(notify_list *lp) { struct sockaddr_in sin; struct status new_status; @@ -252,7 +258,7 @@ process_entry(int sockfd, notify_list *lp) /* __u32 proc, vers, prog; */ if (NL_TIMES(lp) == 0) { - note(N_DEBUG, "%s: Cannot notify %s, giving up.", + xlog(D_GENERAL, "%s: Cannot notify %s, giving up", __func__, inet_ntoa(NL_ADDR(lp))); return 0; } @@ -276,9 +282,9 @@ process_entry(int sockfd, notify_list *lp) new_status.state = NL_STATE(lp); memcpy(new_status.priv, NL_PRIV(lp), SM_PRIV_SIZE); - lp->xid = xmit_call(sockfd, &sin, prog, vers, proc, func, objp); + lp->xid = xmit_call(&sin, prog, vers, proc, func, objp); if (!lp->xid) { - note(N_WARNING, "%s: failed to notify port %d", + xlog_warn("%s: failed to notify port %d", __func__, ntohs(lp->port)); } NL_TIMES(lp) -= 1; @@ -299,22 +305,22 @@ process_reply(FD_SET_TYPE *rfds) if (sockfd == -1 || !FD_ISSET(sockfd, rfds)) return 0; - if (!(lp = recv_rply(sockfd, &sin, &port))) + if (!(lp = recv_rply(&sin, &port))) return 1; if (lp->port == 0) { if (port != 0) { lp->port = htons((unsigned short) port); - process_entry(sockfd, lp); + process_entry(lp); NL_WHEN(lp) = time(NULL) + NOTIFY_TIMEOUT; nlist_remove(¬ify, lp); nlist_insert_timer(¬ify, lp); return 1; } - note(N_WARNING, "%s: [%s] service %d not registered", + xlog_warn("%s: [%s] service %d not registered", __func__, inet_ntoa(lp->addr), NL_MY_PROG(lp)); } else { - dprintf(N_DEBUG, "%s: Callback to %s (for %d) succeeded.", + xlog(D_GENERAL, "%s: Callback to %s (for %d) succeeded", __func__, NL_MY_NAME(lp), NL_MON_NAME(lp)); } nlist_free(¬ify, lp); @@ -331,19 +337,15 @@ process_notify_list(void) { notify_list *entry; time_t now; - int fd; - - if ((fd = statd_get_socket()) < 0) - return 0; while ((entry = notify) != NULL && NL_WHEN(entry) < time(&now)) { - if (process_entry(fd, entry)) { + if (process_entry(entry)) { NL_WHEN(entry) = time(NULL) + NOTIFY_TIMEOUT; nlist_remove(¬ify, entry); nlist_insert_timer(¬ify, entry); } else { - note(N_ERROR, - "%s: Can't callback %s (%d,%d), giving up.", + xlog(L_ERROR, + "%s: Can't callback %s (%d,%d), giving up", __func__, NL_MY_NAME(entry), NL_MY_PROG(entry),