nfs-utils: convert gssd to TI-RPC and add IPv6 support (try #3)
Subsystems (2)
cover nfs-utils: convert gssd to TI-RPC and add IPv6 support (try #3)
This patchset is a second attempt at adding support for IPv6 to rpc.gssd. The main changes from the first set are some minor fixes and changes suggested by Chuck Lever and a change to use common code to spawn a new RPC client. This set is also based on mainline nfs-utils since the requisite patches for it are now there.
The series should be fully bisectable, but I've only really tested the end result for anything other than to see if it compiles. With these patches I've been able to mount an OpenSolaris server using NFSv3/4 + IPv6 + krb5 auth. I've also done testing with builds with only TIRPC enabled and with TIRPC and IPv6 both disabled and haven't seen any regressions.
Specific changes from the last set:
- check the validity of port given by an upcall
- check return code from snprintf()
- switched gssd to use nfs_get_rpcclient()
- pare down hints passed to getaddrinfo() in populate_port()
Jeff Layton (5):
nfs-utils: make getnameinfo() required for --enable-gss
nfs-utils: store the address given in the upcall for later use
nfs-utils: skip getaddrinfo in create_auth_rpc_client unless we need
port
nfs-utils: switch gssd to use standard function for getting an RPC
client
nfs-utils: add IPv6 code to gssd
configure.ac | 2 + utils/gssd/gssd.h | 2 +- utils/gssd/gssd_proc.c | 285 +++++++++++++++++++++++++++++++++--------------- 3 files changed, 202 insertions(+), 87 deletions(-)
PATCH 1/5 nfs-utils: make getnameinfo() required for --enable-gss
Systems that are so old that they don't have getnameinfo() in glibc are probably also running kernels that are so old that they don't support gssapi upcalls anyway.
Make --enable-gss dependent on the presence of the getnameinfo() function. This allows us to reduce some conditional compilation.
--- configure.ac | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
configure.ac +2 -0
@@ -207,6 +207,8 @@ if test "$enable_nfsv4" = yes; then dnl but we need to make sure we get the right version if test "$enable_gss" = yes; then AC_RPCSEC_VERSION + AC_CHECK_FUNC([getnameinfo], , + [AC_MSG_ERROR([Function 'getnameinfo' not found.])]) fi fi
Signature · 1 line
1.6.0.6
Re: [PATCH 1/5] nfs-utils: make getnameinfo() required for --enable-gss
Quoted 24 lines · Jeff Layton
Systems that are so old that they don't have
getnameinfo()in glibc are
probably also running kernels that are so old that they don't support gssapi upcalls anyway.Make --enable-gss dependent on the presence of the
getnameinfo()function. This allows us to reduce some conditional compilation.Signed-off-by Jeff Layton <[email protected]>---
configure.ac | 2 ++1 files changed, 2 insertions(+), 0 deletions(-)configure.ac +2
-0@@ -207,6 +207,8 @@ if test "$enable_nfsv4" = yes; then dnl but we need to make sure we get the right version if test "$enable_gss" = yes; then AC_RPCSEC_VERSION + AC_CHECK_FUNC([getnameinfo], , + [AC_MSG_ERROR([Function 'getnameinfo' not found.])]) fi
Quoted 1 line
fi
This check is only done when enable_nfsv4 is set. Probably a better place for this is in the enable_gss test that is always done, a few paragraphs lower.
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
PATCH 2/5 nfs-utils: store the address given in the upcall for later use
In reply to Jeff LaytonThe current upcall could be more efficient. We first convert the address to a hostname, and then later when we set up the RPC client, we do a hostname lookup to convert it back to an address.
Begin to change this by keeping the address in the clnt_info that we get out of the upcall. Since a sockaddr has a port field, we can also eliminate the port from the clnt_info.
Finally, switch to getnameinfo() instead of gethostbyaddr(). We'll need to use that call anyway when we add support for IPv6.
--- utils/gssd/gssd.h | 2 +- utils/gssd/gssd_proc.c | 92 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 77 insertions(+), 17 deletions(-)
utils/gssd/gssd.h +1 -1
@@ -83,7 +83,7 @@ struct clnt_info {int krb5_poll_index;int spkm3_fd;int spkm3_poll_index; -int port; +struct sockaddr_storage addr; };void init_client_list (void );
utils/gssd/gssd_proc.c +76 -16
132 lines not on this page · raw message
Signature · 1 line
1.6.0.6
Re: [PATCH 2/5] nfs-utils: store the address given in the upcall for later use
Quoted 5 lines · Jeff Layton
The current upcall could be more efficient. We first convert the address
to a hostname, and then later when we set up the RPC client, we do a hostname lookup to convert it back to an address.
Quoted 8 lines
Begin to change this by keeping the address in the
clnt_infothat we get
out of the upcall. Since a sockaddr has a port field, we can also eliminate the port from theclnt_info.Finally, switch to
getnameinfo()instead ofgethostbyaddr(). We'll need
to use that call anyway when we add support for IPv6.
gethostbyaddr(3) supports AF_INET6, too, by the way.
Quoted 28 lines
Signed-off-by Jeff Layton <[email protected]>---
utils/gssd/gssd.h| 2 +-utils/gssd/gssd_proc.c| 92 ++++++++++++++++++++++++++++++++++++++
+--------2 files changed, 77 insertions(+), 17 deletions(-)utils/gssd/gssd.h +1
-1@@ -83,7 +83,7 @@ struct clnt_info {int krb5_poll_index;int spkm3_fd;int spkm3_poll_index; -int port; +struct sockaddr_storage addr; };void init_client_list (void );utils/gssd/gssd_proc.c +0
-0@@ -102,10 +102,65 @@ struct pollfd * pollarray;int pollsize; /* the size of pollaray (in pollfd's) */
Quoted 4 lines
+/*
+ * convert an address string to asockaddr_storagestruct. Returns true
+ * on success and false on failure.
I usually use the term "presentation address string" since that specifically means an IP address expressed as a C string. I guess that's pretty obvious because you use inet_pton() here.
Quoted 4 lines
+ */
utils/gssd/gssd_proc.c +2
-0+static int +addrstr_to_sockaddr(struct sockaddr *sa, const char *addr, constint port)
utils/gssd/gssd_proc.c struct pollfd * pollarray; · line 120
Quoted 10 lines
utils/gssd/gssd_proc.c +10
-0+{ +struct sockaddr_in *s4 = (struct sockaddr_in *) sa; + +if (inet_pton (AF_INET , addr, &s4->sin_addr)) { + s4->sin_family =AF_INET ; + s4->sin_port =htons (port); + }else { +printerr (0 ,"ERROR: unable to convert %s to address\n" , addr); +return 0 ; + }
I've handled these with a switch statement, as you do later in populate_port(). It's merely a question about consistent coding style, but any reason not to take that approach here?
Quoted 22 lines
utils/gssd/gssd_proc.c +22
-0+ +return 1 ; +} + +/* +* convert a sockaddr to a hostname +*/ +static char * +sockaddr_to_hostname (const struct sockaddr *sa,const char *addr) +{ +socklen_t addrlen; +int err; +char *hostname; +char hbuf[NI_MAXHOST ]; + +switch (sa->sa_family) { +case AF_INET : + addrlen =sizeof (struct sockaddr_in ); +break ; +default : +printerr (0 ,"ERROR: unrecognized addr family %d\n" , + sa->sa_family);
utils/gssd/gssd_proc.c struct pollfd * pollarray; · line 152
Quoted 10 lines
utils/gssd/gssd_proc.c +10
-0+return NULL ; + } + + err =getnameinfo (sa, addrlen, hbuf,sizeof (hbuf),NULL ,0 , +NI_NAMEREQD ); +if (err) { +printerr (0 ,"ERROR: unable to resolve %s to hostname: %s\n" , + addr,gai_strerror (err)); +return NULL ; + }
getnameinfo(3) can return EAI_SYSTEM, in which case the real error value is stored in errno Browsing the gai_strerror(3) implementation in glibc-2.7 seems to show that it's just a simple static char table lookup, so it might be good to handle EAI_SYSTEM explicitly here.
Looks like you already do that in populate_port().
Quoted 79 lines
utils/gssd/gssd_proc.c +6
-0+ + hostname =strdup (hbuf); + +return hostname; +} +/* XXX buffer problems: */
static int
read_service_info(char*info_file_name, char **servicename, char **servername,utils/gssd/gssd_proc.c +2
-1- int *prog, int *vers, char **protocol, int *port) { + int *prog, int *vers, char **protocol, + struct sockaddr *addr) {#define INFOBUFLEN 256 char buf[INFOBUFLEN + 1]; static char dummy[128];utils/gssd/gssd_proc.c +16
-12@@ -117,10 +172,9 @@ read_service_info(char *info_file_name, char **servicename, char **servername, char protoname[16];char cb_port[128 ];char *p; -in_addr_t inaddr;int fd =-1 ; -struct hostent *ent =NULL ;int numfields; +int port =0 ; *servicename = *servername = *protocol =NULL ;@@ -160,21 +214,26 @@ read_service_info(char *info_file_name, char **servicename, char **servername, if((*prog != 100003) || ((*vers != 2) && (*vers != 3) && (*vers != 4))) goto fail; -/* create service name */ - inaddr =inet_addr (address); -if (!(ent =gethostbyaddr (&inaddr,sizeof (inaddr),AF_INET ))) { -printerr (0 ,"ERROR: can't resolve server %s name\n" , address); - goto fail; +if (cb_port[0 ] !='\0' ) { + port =atoi (cb_port); +if (port <0 || port >65535 ) + goto fail; } -if (!(*servername =calloc (strlen (ent->h_name) +1 ,1 ))) + +if (!addrstr_to_sockaddr (addr, address, port)) + goto fail; + + *servername =sockaddr_to_hostname (addr, address); +if (*servername ==NULL ) goto fail; -memcpy (*servername, ent->h_name,strlen (ent->h_name)); -snprintf (buf,INFOBUFLEN ,"%s@%s" , service, ent->h_name); + + nbytes =snprintf (buf,INFOBUFLEN ,"%s@%s" , service, *servername); +if (nbytes >INFOBUFLEN ) + goto fail; +if (!(*servicename =calloc (strlen (buf) +1 ,1 ))) goto fail;memcpy (*servicename, buf,strlen (buf)); -if (cb_port[0 ] !='\0' ) - *port =atoi (cb_port);if (!(*protocol = strdup(protoname))) goto fail;utils/gssd/gssd_proc.c +1
-1@@ -251,7 +310,7 @@ process_clnt_dir_files(struct clnt_info * clp)if ((clp->servicename ==NULL ) &&read_service_info (info_file_name, &clp->servicename, &clp->servername, &clp->prog, &clp->vers, - &clp->protocol, &clp->port)) + &clp->protocol, (struct sockaddr *) &clp->addr))return -1 ;return 0 ; }@@ -599,8 +658,9 @@ int create_auth_rpc_client(struct clnt_info *clp, clp->servername, uid);
utils/gssd/gssd_proc.c int create_auth_rpc_client(struct clnt_info *clp, · line 666
Quoted 10 lines
utils/gssd/gssd_proc.c +3
-2goto out_fail; } -if (clp->port) - ((struct sockaddr_in *)a->ai_addr)->sin_port =htons (clp->port); +if (((struct sockaddr_in ) clp->addr).sin_port !=0 ) + ((struct sockaddr_in *) a->ai_addr)->sin_port = + ((struct sockaddr_in ) clp->addr).sin_port; if (a->ai_protocol == IPPROTO_TCP) { if ((rpc_clnt = clnttcp_create( (struct sockaddr_in *) a->ai_addr,
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
Re: [PATCH 2/5] nfs-utils: store the address given in the upcall for later use
Quoted 45 lines · On Mon, 6 Apr 2009 11:35:50 -0400 Chuck Lever <[email protected]> wrote:
Quoted 5 lines · Jeff Layton
The current upcall could be more efficient. We first convert the address
to a hostname, and then later when we set up the RPC client, we do a hostname lookup to convert it back to an address.Quoted 8 lines
Begin to change this by keeping the address in the
clnt_infothat we get
out of the upcall. Since a sockaddr has a port field, we can also eliminate the port from theclnt_info.Finally, switch to
getnameinfo()instead ofgethostbyaddr(). We'll need
to use that call anyway when we add support for IPv6.gethostbyaddr(3) supports
AF_INET6, too, by the way.Quoted 28 lines
Signed-off-by Jeff Layton <[email protected]>---
utils/gssd/gssd.h| 2 +-utils/gssd/gssd_proc.c| 92 ++++++++++++++++++++++++++++++++++++++
+--------2 files changed, 77 insertions(+), 17 deletions(-)utils/gssd/gssd.h +1
-1@@ -83,7 +83,7 @@ struct clnt_info {int krb5_poll_index;int spkm3_fd;int spkm3_poll_index; -int port; +struct sockaddr_storage addr; };void init_client_list (void );utils/gssd/gssd_proc.c +0
-0@@ -102,10 +102,65 @@ struct pollfd * pollarray;int pollsize; /* the size of pollaray (in pollfd's) */
Quoted 9 lines
Quoted 4 lines
+/*
+ * convert an address string to asockaddr_storagestruct. Returns true
+ * on success and false on failure.I usually use the term "presentation address string" since that specifically means an IP address expressed as a C string. I guess that's pretty obvious because you use
inet_pton()here.
Sounds reasonable.
Quoted 10 lines
Quoted 10 lines
+ */
utils/gssd/gssd_proc.c +2
-0+static int +addrstr_to_sockaddr(struct sockaddr *sa, const char *addr, constint port)
utils/gssd/gssd_proc.c +6
-0+{ +struct sockaddr_in *s4 = (struct sockaddr_in *) sa; + +if (inet_pton (AF_INET , addr, &s4->sin_addr)) { + s4->sin_family =AF_INET ; + s4->sin_port =htons (port);
Quoted 9 lines
utils/gssd/gssd_proc.c struct pollfd * pollarray; · line 120
Quoted 4 lines
utils/gssd/gssd_proc.c +4
-0+ }else { +printerr (0 ,"ERROR: unable to convert %s to address\n" , addr); +return 0 ; + }I've handled these with a switch statement, as you do later in
populate_port(). It's merely a question about consistent coding style, but any reason not to take that approach here?
Yes. switch statements are really only suitable when you have a simple value to compare against. We're not comparing the address family here because it's not yet known. We have to try and convert this opaque string to an address first.
In the last patch, I add an "else if" where we try to convert it to an ipv6 addr, but we can't really do "try this and if that fails then try this" in the context of a switch.
In other places I try to use switches where it's suitable...
Quoted 38 lines
Quoted 22 lines
utils/gssd/gssd_proc.c +22
-0+ +return 1 ; +} + +/* +* convert a sockaddr to a hostname +*/ +static char * +sockaddr_to_hostname (const struct sockaddr *sa,const char *addr) +{ +socklen_t addrlen; +int err; +char *hostname; +char hbuf[NI_MAXHOST ]; + +switch (sa->sa_family) { +case AF_INET : + addrlen =sizeof (struct sockaddr_in ); +break ; +default : +printerr (0 ,"ERROR: unrecognized addr family %d\n" , + sa->sa_family);utils/gssd/gssd_proc.c struct pollfd * pollarray; · line 152
Quoted 10 lines
utils/gssd/gssd_proc.c +10
-0+return NULL ; + } + + err =getnameinfo (sa, addrlen, hbuf,sizeof (hbuf),NULL ,0 , +NI_NAMEREQD ); +if (err) { +printerr (0 ,"ERROR: unable to resolve %s to hostname: %s\n" , + addr,gai_strerror (err)); +return NULL ; + }getnameinfo(3) can return
EAI_SYSTEM, in which case the real error value is stored in errno Browsing thegai_strerror(3)implementation in glibc-2.7 seems to show that it's just a simple static char table lookup, so it might be good to handleEAI_SYSTEMexplicitly here.
Quoted 2 lines
Looks like you already do that in
populate_port().
Good catch. Will fix...
Quoted 93 lines
Quoted 79 lines
utils/gssd/gssd_proc.c +6
-0+ + hostname =strdup (hbuf); + +return hostname; +} +/* XXX buffer problems: */
static int
read_service_info(char*info_file_name, char **servicename, char **servername,utils/gssd/gssd_proc.c +2
-1- int *prog, int *vers, char **protocol, int *port) { + int *prog, int *vers, char **protocol, + struct sockaddr *addr) {#define INFOBUFLEN 256 char buf[INFOBUFLEN + 1]; static char dummy[128];utils/gssd/gssd_proc.c +16
-12@@ -117,10 +172,9 @@ read_service_info(char *info_file_name, char **servicename, char **servername, char protoname[16];char cb_port[128 ];char *p; -in_addr_t inaddr;int fd =-1 ; -struct hostent *ent =NULL ;int numfields; +int port =0 ; *servicename = *servername = *protocol =NULL ;@@ -160,21 +214,26 @@ read_service_info(char *info_file_name, char **servicename, char **servername, if((*prog != 100003) || ((*vers != 2) && (*vers != 3) && (*vers != 4))) goto fail; -/* create service name */ - inaddr =inet_addr (address); -if (!(ent =gethostbyaddr (&inaddr,sizeof (inaddr),AF_INET ))) { -printerr (0 ,"ERROR: can't resolve server %s name\n" , address); - goto fail; +if (cb_port[0 ] !='\0' ) { + port =atoi (cb_port); +if (port <0 || port >65535 ) + goto fail; } -if (!(*servername =calloc (strlen (ent->h_name) +1 ,1 ))) + +if (!addrstr_to_sockaddr (addr, address, port)) + goto fail; + + *servername =sockaddr_to_hostname (addr, address); +if (*servername ==NULL ) goto fail; -memcpy (*servername, ent->h_name,strlen (ent->h_name)); -snprintf (buf,INFOBUFLEN ,"%s@%s" , service, ent->h_name); + + nbytes =snprintf (buf,INFOBUFLEN ,"%s@%s" , service, *servername); +if (nbytes >INFOBUFLEN ) + goto fail; +if (!(*servicename =calloc (strlen (buf) +1 ,1 ))) goto fail;memcpy (*servicename, buf,strlen (buf)); -if (cb_port[0 ] !='\0' ) - *port =atoi (cb_port);if (!(*protocol = strdup(protoname))) goto fail;utils/gssd/gssd_proc.c +1
-1@@ -251,7 +310,7 @@ process_clnt_dir_files(struct clnt_info * clp)if ((clp->servicename ==NULL ) &&read_service_info (info_file_name, &clp->servicename, &clp->servername, &clp->prog, &clp->vers, - &clp->protocol, &clp->port)) + &clp->protocol, (struct sockaddr *) &clp->addr))return -1 ;return 0 ; }@@ -599,8 +658,9 @@ int create_auth_rpc_client(struct clnt_info *clp, clp->servername, uid);utils/gssd/gssd_proc.c int create_auth_rpc_client(struct clnt_info *clp, · line 666
Quoted 10 lines
utils/gssd/gssd_proc.c +3
-2goto out_fail; } -if (clp->port) - ((struct sockaddr_in *)a->ai_addr)->sin_port =htons (clp->port); +if (((struct sockaddr_in ) clp->addr).sin_port !=0 ) + ((struct sockaddr_in *) a->ai_addr)->sin_port = + ((struct sockaddr_in ) clp->addr).sin_port; if (a->ai_protocol == IPPROTO_TCP) { if ((rpc_clnt = clnttcp_create( (struct sockaddr_in *) a->ai_addr,--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH 2/5] nfs-utils: store the address given in the upcall for later use
Quoted 23 lines · Jeff Layton
Quoted 11 lines · On Mon, 6 Apr 2009 11:35:50 -0400 Chuck Lever <[email protected]> wrote:
Quoted 10 lines · Jeff Layton
+ */
(quoted diff) +2
-0+static int +addrstr_to_sockaddr(struct sockaddr *sa, const char *addr, constint port)
utils/gssd/gssd_proc.c +6
-0+{ +struct sockaddr_in *s4 = (struct sockaddr_in *) sa; + +if (inet_pton (AF_INET , addr, &s4->sin_addr)) { + s4->sin_family =AF_INET ; + s4->sin_port =htons (port);Quoted 9 lines
utils/gssd/gssd_proc.c struct pollfd * pollarray; · line 120
Quoted 4 lines
utils/gssd/gssd_proc.c +4
-0+ }else { +printerr (0 ,"ERROR: unable to convert %s to address\n" , addr); +return 0 ; + }I've handled these with a switch statement, as you do later in
populate_port(). It's merely a question about consistent coding style, but any reason not to take that approach here?
Quoted 8 lines
Yes. switch statements are really only suitable when you have a simple value to compare against. We're not comparing the address family here because it's not yet known. We have to try and convert this opaque string to an address first.
In the last patch, I add an "else if" where we try to convert it to an ipv6 addr, but we can't really do "try this and if that fails then try this" in the context of a switch.
Just avoid doing the "break;" if inet_ntop(AF_INET6) fails. Just a suggestion. Some might feel that's too clever.
Quoted 1 line
In other places I try to use switches where it's suitable...
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
PATCH 3/5 nfs-utils: skip getaddrinfo in create_auth_rpc_client unless we need port
In reply to Jeff LaytonWe already have the server's address from the upcall, so we don't really need to look it up again. Move the getaddrinfo call in create_auth_rpc_client to a new function. Skip it if we already have the port in the sockaddr that we saved from the info in the upcall. If we need to get the port, don't bother looking up the hostname, just do the getaddrinfo with AI_NUMERICHOST set.
This should reduce the amount of lookups that are needed.
--- utils/gssd/gssd_proc.c | 130 ++++++++++++++++++++++++++++------------------- 1 files changed, 77 insertions(+), 53 deletions(-)
utils/gssd/gssd_proc.c +77 -53
@@ -540,6 +540,74 @@ out_err: }/* +* Determine the port from the servicename and set the right field in the +* sockaddr. This is mostly a no-op with newer kernels that send the port +* in the upcall. Returns true on success and false on failure. +*/ +static int +populate_port (struct sockaddr *sa,char *servicename,int protocol) +{ +struct sockaddr_in *s4 = (struct sockaddr_in *) sa; +char service[64 ]; +char *at_sign; +int errcode; +struct addrinfo *a =NULL ; +struct addrinfo ai_hints = { .ai_family = sa->sa_family, + .ai_protocol = protocol, + .ai_flags =AI_NUMERICHOST }; + +/* +* Newer kernels send the port in the upcall. If we already have +* the port, there's no need to look it up. +*/ +switch (sa->sa_family) { +case AF_INET : +if (s4->sin_port !=0 ) { +printerr (2 ,"DEBUG: port already set to %d\n" , +ntohs (s4->sin_port)); +return 1 ; + } +break ; +default : +printerr (0 ,"ERROR: unsupported address family %d\n" , + sa->sa_family); +return 0 ; + } + +/* extract the service name from clp->servicename */ +if ((at_sign =strchr (servicename,'@' )) ==NULL ) { +printerr (0 ,"WARNING: servicename (%s) not formatted as " +"expected with service@host\n" , servicename); +return 0 ; + } +if ((at_sign - servicename) >=sizeof (service)) { +printerr (0 ,"WARNING: service portion of servicename (%s) " +"is too long!\n" , servicename); +return 0 ; + } +strncpy (service, servicename, at_sign - servicename); + service[at_sign - servicename] ='\0' ; + + errcode =getaddrinfo (NULL , service, &ai_hints, &a); +if (errcode) { +printerr (0 ,"WARNING: Error from getaddrinfo for service " +"'%s': %s\n" , service, + errcode ==EAI_SYSTEM ?strerror (errno) : +gai_strerror (errcode)); +return 0 ; + } + +if (a->ai_family ==AF_INET ) + s4->sin_port = ((struct sockaddr_in *) a->ai_addr)->sin_port; +else +printerr (0 ,"ERROR: unrecognized address family %d returned " +"by getaddrinfo.\n" , a->ai_family); + +freeaddrinfo (a); +return 1 ; +} + +/* * Create an RPC connection and establish an authenticated * gss context with a server. */
@@ -554,14 +622,12 @@ int create_auth_rpc_client(struct clnt_info *clp,AUTH *auth =NULL ;uid_t save_uid =-1 ;int retval =-1 ; -int errcode;OM_uint32 min_stat;char rpc_errmsg[1024 ];int sockp =RPC_ANYSOCK ;int sendsz =32768 , recvsz =32768 ; -struct addrinfo ai_hints, *a =NULL ; -char service[64 ]; -char *at_sign; +int protocol; +struct sockaddr *addr = (struct sockaddr *) &clp->addr;/* Create the context as the user (not as root) */ save_uid =geteuid ();
@@ -615,15 +681,10 @@ int create_auth_rpc_client(struct clnt_info *clp,printerr (2 ,"creating %s client for server %s\n" , clp->protocol, clp->servername); -memset (&ai_hints,'\0' ,sizeof (ai_hints)); - ai_hints.ai_family =PF_INET ; - ai_hints.ai_flags |=AI_CANONNAME ;if ((strcmp (clp->protocol,"tcp" )) ==0 ) { - ai_hints.ai_socktype =SOCK_STREAM ; - ai_hints.ai_protocol =IPPROTO_TCP ; + protocol =IPPROTO_TCP ; }else if ((strcmp (clp->protocol,"udp" )) ==0 ) { - ai_hints.ai_socktype =SOCK_DGRAM ; - ai_hints.ai_protocol =IPPROTO_UDP ; + protocol =IPPROTO_UDP ; }else { printerr(0, "WARNING: unrecognized protocol, '%s', requested " "for connection to server %s for user with uid %d\n",
@@ -631,39 +692,12 @@ int create_auth_rpc_client(struct clnt_info *clp, goto out_fail; } -/* extract the service name from clp->servicename */ -if ((at_sign =strchr (clp->servicename,'@' )) ==NULL ) { -printerr (0 ,"WARNING: servicename (%s) not formatted as " -"expected with service@host\n" , clp->servicename); - goto out_fail; - } -if ((at_sign - clp->servicename) >=sizeof (service)) { -printerr (0 ,"WARNING: service portion of servicename (%s) " -"is too long!\n" , clp->servicename); - goto out_fail; - } -strncpy (service, clp->servicename, at_sign - clp->servicename); - service[at_sign - clp->servicename] ='\0' ; - - errcode =getaddrinfo (clp->servername, service, &ai_hints, &a); -if (errcode) { -printerr (0 ,"WARNING: Error from getaddrinfo for server " -"'%s': %s\n" , clp->servername,gai_strerror (errcode)); +if (!populate_port (addr, clp->servicename, protocol)) goto out_fail; - } -if (a ==NULL ) { -printerr (0 ,"WARNING: No address information found for " -"connection to server %s for user with uid %d\n" , - clp->servername, uid); - goto out_fail; - } -if (((struct sockaddr_in ) clp->addr).sin_port !=0 ) - ((struct sockaddr_in *) a->ai_addr)->sin_port = - ((struct sockaddr_in ) clp->addr).sin_port; -if (a->ai_protocol ==IPPROTO_TCP ) { +if (protocol ==IPPROTO_TCP ) {if ((rpc_clnt =clnttcp_create ( - (struct sockaddr_in *) a->ai_addr, + (struct sockaddr_in *) &clp->addr, clp->prog, clp->vers, &sockp, sendsz, recvsz)) ==NULL ) { snprintf(rpc_errmsg, sizeof(rpc_errmsg),
@@ -674,10 +708,10 @@ int create_auth_rpc_client(struct clnt_info *clp, clnt_spcreateerror(rpc_errmsg)); goto out_fail; } - }else if (a->ai_protocol ==IPPROTO_UDP ) { + }else if (protocol ==IPPROTO_UDP ) {const struct timeval timeout = {5 ,0 };if ((rpc_clnt =clntudp_bufcreate ( - (struct sockaddr_in *) a->ai_addr, + (struct sockaddr_in *) &clp->addr, clp->prog, clp->vers, timeout, &sockp, sendsz, recvsz)) ==NULL ) { snprintf(rpc_errmsg, sizeof(rpc_errmsg),
@@ -688,16 +722,7 @@ int create_auth_rpc_client(struct clnt_info *clp, clnt_spcreateerror(rpc_errmsg)); goto out_fail; } - }else { -/* Shouldn't happen! */ -printerr (0 ,"ERROR: requested protocol '%s', but " -"got addrinfo with protocol %d\n" , - clp->protocol, a->ai_protocol); - goto out_fail; } -/* We're done with this */ -freeaddrinfo (a); - a =NULL ;printerr (2 ,"creating context with server %s\n" , clp->servicename); auth =authgss_create_default (rpc_clnt, clp->servicename, &sec);
@@ -719,7 +744,6 @@ int create_auth_rpc_client(struct clnt_info *clp, out:if (sec.cred !=GSS_C_NO_CREDENTIAL )gss_release_cred (&min_stat, &sec.cred); -if (a !=NULL )freeaddrinfo (a);/* Restore euid to original value */ if ((save_uid !=-1 ) && (setfsuid (save_uid) != uid)) { printerr(0, "WARNING: Failed to restore fsuid"
Signature · 1 line
1.6.0.6
PATCH 4/5 nfs-utils: switch gssd to use standard function for getting an RPC client
In reply to Jeff LaytonWe already have a common function for setting up an RPC client. Switch gssd to use it.
--- utils/gssd/gssd_proc.c | 53 +++++++++++++++++++++-------------------------- 1 files changed, 24 insertions(+), 29 deletions(-)
utils/gssd/gssd_proc.c +24 -29
@@ -72,6 +72,7 @@#include "gss_util.h" #include "krb5_util.h" #include "context.h" +#include "nfsrpc.h" /* * pollarray:
@@ -624,10 +625,10 @@ int create_auth_rpc_client(struct clnt_info *clp,int retval =-1 ;OM_uint32 min_stat;char rpc_errmsg[1024 ]; -int sockp =RPC_ANYSOCK ; -int sendsz =32768 , recvsz =32768 ;int protocol; +struct timeval timeout = {5 ,0 };struct sockaddr *addr = (struct sockaddr *) &clp->addr; +socklen_t salen;/* Create the context as the user (not as root) */ save_uid =geteuid ();
@@ -695,33 +696,27 @@ int create_auth_rpc_client(struct clnt_info *clp,if (!populate_port (addr, clp->servicename, protocol)) goto out_fail; -if (protocol ==IPPROTO_TCP ) { -if ((rpc_clnt =clnttcp_create ( - (struct sockaddr_in *) &clp->addr, - clp->prog, clp->vers, &sockp, - sendsz, recvsz)) ==NULL ) { -snprintf (rpc_errmsg,sizeof (rpc_errmsg), -"WARNING: can't create tcp rpc_clnt " -"for server %s for user with uid %d" , - clp->servername, uid); -printerr (0 ,"%s\n" , -clnt_spcreateerror (rpc_errmsg)); - goto out_fail; - } - }else if (protocol ==IPPROTO_UDP ) { -const struct timeval timeout = {5 ,0 }; -if ((rpc_clnt =clntudp_bufcreate ( - (struct sockaddr_in *) &clp->addr, - clp->prog, clp->vers, timeout, - &sockp, sendsz, recvsz)) ==NULL ) { -snprintf (rpc_errmsg,sizeof (rpc_errmsg), -"WARNING: can't create udp rpc_clnt " -"for server %s for user with uid %d" , - clp->servername, uid); -printerr (0 ,"%s\n" , -clnt_spcreateerror (rpc_errmsg)); - goto out_fail; - } +switch (addr->sa_family) { +case AF_INET : + salen =sizeof (struct sockaddr_in ); +break ; +default : +printerr (1 ,"ERROR: Unknown address family %d\n" , + addr->sa_family); + goto out_fail; + } + + rpc_clnt =nfs_get_rpcclient (addr, salen, protocol, clp->prog, + clp->vers, &timeout); +if (!rpc_clnt) { +snprintf (rpc_errmsg,sizeof (rpc_errmsg), +"WARNING: can't create %s rpc_clnt to server %s for " +"user with uid %d" , + protocol ==IPPROTO_TCP ?"tcp" :"udp" , + clp->servername, uid); +printerr (0 ,"%s\n" , +clnt_spcreateerror (rpc_errmsg)); + goto out_fail; }printerr (2 ,"creating context with server %s\n" , clp->servicename);
Signature · 1 line
1.6.0.6
Re: [PATCH 4/5] nfs-utils: switch gssd to use standard function for getting an RPC client
Quoted 2 lines · Jeff Layton
We already have a common function for setting up an RPC client. Switch gssd to use it.
Maybe this is a nit, but I would like a stronger justification... like "switch to a function that can support IPv6".
Quoted 87 lines
Signed-off-by Jeff Layton <[email protected]>---
utils/gssd/gssd_proc.c| 53 ++++++++++++++++++++
+--------------------------1 files changed, 24 insertions(+), 29 deletions(-)utils/gssd/gssd_proc.c +3
-2@@ -72,6 +72,7 @@#include "gss_util.h" #include "krb5_util.h" #include "context.h" +#include "nfsrpc.h" /* * pollarray: @@ -624,10 +625,10 @@ int create_auth_rpc_client(struct clnt_info *clp, int retval = -1;OM_uint32 min_stat;char rpc_errmsg[1024 ]; -int sockp =RPC_ANYSOCK ; -int sendsz =32768 , recvsz =32768 ;int protocol; +struct timeval timeout = {5 ,0 };struct sockaddr *addr = (struct sockaddr *) &clp->addr; +socklen_t salen;/* Create the context as the user (not as root) */ save_uid = geteuid();utils/gssd/gssd_proc.c +21
-27@@ -695,33 +696,27 @@ int create_auth_rpc_client(struct clnt_info *clp, if (!populate_port(addr, clp->servicename, protocol)) goto out_fail; -if (protocol ==IPPROTO_TCP ) { -if ((rpc_clnt =clnttcp_create ( - (struct sockaddr_in *) &clp->addr, - clp->prog, clp->vers, &sockp, - sendsz, recvsz)) ==NULL ) { -snprintf (rpc_errmsg,sizeof (rpc_errmsg), -"WARNING: can't create tcp rpc_clnt " -"for server %s for user with uid %d" , - clp->servername, uid); -printerr (0 ,"%s\n" , -clnt_spcreateerror (rpc_errmsg)); - goto out_fail; - } - }else if (protocol ==IPPROTO_UDP ) { -const struct timeval timeout = {5 ,0 }; -if ((rpc_clnt =clntudp_bufcreate ( - (struct sockaddr_in *) &clp->addr, - clp->prog, clp->vers, timeout, - &sockp, sendsz, recvsz)) ==NULL ) { -snprintf (rpc_errmsg,sizeof (rpc_errmsg), -"WARNING: can't create udp rpc_clnt " -"for server %s for user with uid %d" , - clp->servername, uid); -printerr (0 ,"%s\n" , -clnt_spcreateerror (rpc_errmsg)); - goto out_fail; - } +switch (addr->sa_family) { +case AF_INET : + salen =sizeof (struct sockaddr_in ); +break ; +default : +printerr (1 ,"ERROR: Unknown address family %d\n" , + addr->sa_family); + goto out_fail; + } + + rpc_clnt =nfs_get_rpcclient (addr, salen, protocol, clp->prog, + clp->vers, &timeout); +if (!rpc_clnt) { +snprintf (rpc_errmsg,sizeof (rpc_errmsg), +"WARNING: can't create %s rpc_clnt to server %s for " +"user with uid %d" , + protocol ==IPPROTO_TCP ?"tcp" :"udp" , + clp->servername, uid); +printerr (0 ,"%s\n" , +clnt_spcreateerror (rpc_errmsg)); + goto out_fail; }
Quoted 1 line
printerr(2, "creating context with server %s\n", clp->servicename);
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
PATCH 5/5 nfs-utils: add IPv6 code to gssd
In reply to Jeff LaytonAll of the pieces to handle IPv6 are now in place. Add IPv6-specific code wrapped in the proper #ifdef's so that IPv6 support works when it's enabled at build-time.
--- utils/gssd/gssd_proc.c | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-)
utils/gssd/gssd_proc.c +34 -0
@@ -111,10 +111,18 @@ static int addrstr_to_sockaddr(struct sockaddr *sa, const char *addr, const int port) { struct sockaddr_in *s4 = (struct sockaddr_in *) sa; +#ifdef IPV6_SUPPORTED +struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) sa; +#endif /* IPV6_SUPPORTED */ if (inet_pton (AF_INET , addr, &s4->sin_addr)) { s4->sin_family =AF_INET ; s4->sin_port =htons (port); +#ifdef IPV6_SUPPORTED + }else if (inet_pton (AF_INET6 , addr, &s6->sin6_addr)) { + s6->sin6_family =AF_INET6 ; + s6->sin6_port =htons (port); +#endif /* IPV6_SUPPORTED */ }else {printerr (0 ,"ERROR: unable to convert %s to address\n" , addr);return 0 ;
@@ -138,6 +146,11 @@ sockaddr_to_hostname(const struct sockaddr *sa, const char *addr)case AF_INET : addrlen =sizeof (struct sockaddr_in );break ; +#ifdef IPV6_SUPPORTED +case AF_INET6 : + addrlen =sizeof (struct sockaddr_in6 ); +break ; +#endif /* IPV6_SUPPORTED */ default :printerr (0 ,"ERROR: unrecognized addr family %d\n" , sa->sa_family);
@@ -549,6 +562,9 @@ static int populate_port(struct sockaddr *sa, char *servicename, int protocol) { struct sockaddr_in *s4 = (struct sockaddr_in *) sa; +#ifdef IPV6_SUPPORTED +struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) sa; +#endif /* IPV6_SUPPORTED */ char service[64 ];char *at_sign;int errcode;
@@ -569,6 +585,15 @@ populate_port(struct sockaddr *sa, char *servicename, int protocol)return 1 ; }break ; +#ifdef IPV6_SUPPORTED +case AF_INET6 : +if (s6->sin6_port !=0 ) { +printerr (2 ,"DEBUG: port already set to %d\n" , +ntohs (s6->sin6_port)); +return 1 ; + } +break ; +#endif /* IPV6_SUPPORTED */ default :printerr (0 ,"ERROR: unsupported address family %d\n" , sa->sa_family);
@@ -600,6 +625,10 @@ populate_port(struct sockaddr *sa, char *servicename, int protocol)if (a->ai_family ==AF_INET ) s4->sin_port = ((struct sockaddr_in *) a->ai_addr)->sin_port; +#ifdef IPV6_SUPPORTED + else if (a->ai_family == AF_INET6) + s6->sin6_port = ((struct sockaddr_in6 *) a->ai_addr)->sin6_port; +#endif /* IPV6_SUPPORTED */ else printerr(0, "ERROR: unrecognized address family %d returned " "by getaddrinfo.\n", a->ai_family);
@@ -700,6 +729,11 @@ int create_auth_rpc_client(struct clnt_info *clp,case AF_INET : salen =sizeof (struct sockaddr_in );break ; +#ifdef IPV6_SUPPORTED +case AF_INET6 : + salen =sizeof (struct sockaddr_in6 ); +break ; +#endif /* IPV6_SUPPORTED */ default :printerr (1 ,"ERROR: Unknown address family %d\n" , addr->sa_family);
Signature · 1 line
1.6.0.6
Re: [PATCH 5/5] nfs-utils: add IPv6 code to gssd
Quoted 25 lines · Jeff Layton
All of the pieces to handle IPv6 are now in place. Add IPv6-specific code wrapped in the proper #ifdef's so that IPv6 support works when it's enabled at build-time.
Signed-off-by Jeff Layton <[email protected]>---
utils/gssd/gssd_proc.c| 34 ++++++++++++++++++++++++++++++++++1 files changed, 34 insertions(+), 0 deletions(-)utils/gssd/gssd_proc.c +0
-0@@ -111,10 +111,18 @@ static int
addrstr_to_sockaddr(struct sockaddr *sa, const char *addr, const int port){ struct sockaddr_in *s4 = (struct sockaddr_in *) sa;utils/gssd/gssd_proc.c +3
-0+#ifdef IPV6_SUPPORTED +struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) sa; +#endif /* IPV6_SUPPORTED */ if (inet_pton(AF_INET, addr, &s4->sin_addr)) { s4->sin_family = AF_INET; s4->sin_port = htons(port);
utils/gssd/gssd_proc.c static int · line 125
Quoted 5 lines
utils/gssd/gssd_proc.c +5
-0+#ifdef IPV6_SUPPORTED + }else if (inet_pton (AF_INET6 , addr, &s6->sin6_addr)) { + s6->sin6_family =AF_INET6 ; + s6->sin6_port =htons (port); +#endif /* IPV6_SUPPORTED */
Does this support scope IDs? Do we expect to get a link-local IPv6 address here?
Quoted 57 lines
} else { printerr(0, "ERROR: unable to convert %s to address\n", addr); return 0;utils/gssd/gssd_proc.c +5
-0@@ -138,6 +146,11 @@ sockaddr_to_hostname(const struct sockaddr *sa, const char *addr)case AF_INET : addrlen =sizeof (struct sockaddr_in );break ; +#ifdef IPV6_SUPPORTED +case AF_INET6 : + addrlen =sizeof (struct sockaddr_in6 ); +break ; +#endif /* IPV6_SUPPORTED */ default : printerr(0, "ERROR: unrecognized addr family %d\n",sa->sa_family);utils/gssd/gssd_proc.c +12
-0@@ -549,6 +562,9 @@ static int populate_port(struct sockaddr *sa, char *servicename, int protocol) { struct sockaddr_in *s4 = (struct sockaddr_in *) sa; +#ifdef IPV6_SUPPORTED +struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) sa; +#endif /* IPV6_SUPPORTED */ char service[64 ];char *at_sign;int errcode;@@ -569,6 +585,15 @@ populate_port(struct sockaddr *sa, char *servicename, int protocol)return 1 ; }break ; +#ifdef IPV6_SUPPORTED +case AF_INET6 : +if (s6->sin6_port !=0 ) { +printerr (2 ,"DEBUG: port already set to %d\n" , +ntohs (s6->sin6_port)); +return 1 ; + } +break ; +#endif /* IPV6_SUPPORTED */ default : printerr(0, "ERROR: unsupported address family %d\n",sa->sa_family);utils/gssd/gssd_proc.c +4
-0@@ -600,6 +625,10 @@ populate_port(struct sockaddr *sa, char *servicename, int protocol)if (a->ai_family ==AF_INET ) s4->sin_port = ((struct sockaddr_in *) a->ai_addr)->sin_port; +#ifdef IPV6_SUPPORTED + else if (a->ai_family == AF_INET6) + s6->sin6_port = ((struct sockaddr_in6 *) a->ai_addr)->sin6_port; +#endif /* IPV6_SUPPORTED */ else printerr(0, "ERROR: unrecognized address family %d returned ""by getaddrinfo.\n", a->ai_family);utils/gssd/gssd_proc.c +0
-0@@ -700,6 +729,11 @@ int create_auth_rpc_client(struct clnt_info *clp,case AF_INET :
utils/gssd/gssd_proc.c int create_auth_rpc_client(struct clnt_info *clp, · line 739
Quoted 10 lines
utils/gssd/gssd_proc.c +5
-0salen =sizeof (struct sockaddr_in );break ; +#ifdef IPV6_SUPPORTED +case AF_INET6 : + salen =sizeof (struct sockaddr_in6 ); +break ; +#endif /* IPV6_SUPPORTED */ default :printerr (1 ,"ERROR: Unknown address family %d\n" , addr->sa_family);
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
Re: [PATCH 5/5] nfs-utils: add IPv6 code to gssd
Quoted 23 lines · On Mon, 6 Apr 2009 11:35:21 -0400 Chuck Lever <[email protected]> wrote:
Quoted 22 lines · Jeff Layton
All of the pieces to handle IPv6 are now in place. Add IPv6-specific code wrapped in the proper #ifdef's so that IPv6 support works when it's enabled at build-time.
Signed-off-by Jeff Layton <[email protected]>---
utils/gssd/gssd_proc.c| 34 ++++++++++++++++++++++++++++++++++1 files changed, 34 insertions(+), 0 deletions(-)utils/gssd/gssd_proc.c +0
-0@@ -111,10 +111,18 @@ static int
addrstr_to_sockaddr(struct sockaddr *sa, const char *addr, const int port){ struct sockaddr_in *s4 = (struct sockaddr_in *) sa;utils/gssd/gssd_proc.c +3
-0+#ifdef IPV6_SUPPORTED +struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) sa; +#endif /* IPV6_SUPPORTED */
Quoted 12 lines
utils/gssd/gssd_proc.c static int · line 125
Quoted 8 lines
if (inet_pton(AF_INET, addr, &s4->sin_addr)) { s4->sin_family = AF_INET; s4->sin_port = htons(port);utils/gssd/gssd_proc.c +5
-0+#ifdef IPV6_SUPPORTED + }else if (inet_pton (AF_INET6 , addr, &s6->sin6_addr)) { + s6->sin6_family =AF_INET6 ; + s6->sin6_port =htons (port); +#endif /* IPV6_SUPPORTED */ Does this support scope IDs? Do we expect to get a link-local IPv6 address here?
It doesn't support scope ID's. The upcall doesn't send the scopeid if there's one defined.
Given that we rely on name resolution to some degree with krb5 auth, I'm not sure that it makes much sense to deal with scopeid's here. AAAA records in DNS don't have space for them.
PS: I'll fix the getnameinfo() autoconf patch to do what you suggest...
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH 5/5] nfs-utils: add IPv6 code to gssd
Quoted 39 lines · Jeff Layton
Quoted 23 lines · On Mon, 6 Apr 2009 11:35:21 -0400 Chuck Lever <[email protected]> wrote:
Quoted 22 lines · Jeff Layton
All of the pieces to handle IPv6 are now in place. Add IPv6-specific code wrapped in the proper #ifdef's so that IPv6 support works when it's enabled at build-time.
Signed-off-by Jeff Layton <[email protected]>---
utils/gssd/gssd_proc.c| 34 ++++++++++++++++++++++++++++++++++1 files changed, 34 insertions(+), 0 deletions(-)utils/gssd/gssd_proc.c +0
-0@@ -111,10 +111,18 @@ static int
addrstr_to_sockaddr(struct sockaddr *sa, const char *addr, const int port){ struct sockaddr_in *s4 = (struct sockaddr_in *) sa;utils/gssd/gssd_proc.c +3
-0+#ifdef IPV6_SUPPORTED +struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) sa; +#endif /* IPV6_SUPPORTED */ Quoted 12 lines
utils/gssd/gssd_proc.c static int · line 125
Quoted 8 lines
if (inet_pton(AF_INET, addr, &s4->sin_addr)) { s4->sin_family = AF_INET; s4->sin_port = htons(port);utils/gssd/gssd_proc.c +5
-0+#ifdef IPV6_SUPPORTED + }else if (inet_pton (AF_INET6 , addr, &s6->sin6_addr)) { + s6->sin6_family =AF_INET6 ; + s6->sin6_port =htons (port); +#endif /* IPV6_SUPPORTED */ Does this support scope IDs? Do we expect to get a link-local IPv6 address here?
Quoted 7 lines
It doesn't support scope ID's. The upcall doesn't send the scopeid if there's one defined.
Given that we rely on name resolution to some degree with krb5 auth, I'm not sure that it makes much sense to deal with scopeid's here. AAAA
records in DNS don't have space for them.
I think that's worth mentioning somewhere in the comments or in the man page -- a hostname is required in here, it won't work with raw addresses. So link-local support is right out.
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com