]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
rpc.mountd: Change nfs_client->m_hostname to be a dynamically-allocated string
authorJeff Layton <jlayton@redhat.com>
Thu, 27 Sep 2007 10:53:48 +0000 (06:53 -0400)
committerNeil Brown <neilb@suse.de>
Fri, 28 Sep 2007 01:39:56 +0000 (11:39 +1000)
Change nfs_client->m_hostname to be dynamically allocated rather than a
fixed length array of size NFSCLNT_IDMAX. This also adds a bit of
micro-optimization in a few places since it reduces the amount of string
copying that needs to be done.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Acked-by: Steve Dickson <steved@redhat.com>
Signed-off-by: Neil Brown <neilb@suse.de>
support/export/client.c
support/include/exportfs.h
utils/mountd/auth.c

index 19b53aaa5f831be97aa859ea27470e0c70a95b40..1754aa0d0d630f25962c3a4abd89bab9a118e7cc 100644 (file)
@@ -118,6 +118,7 @@ client_dup(nfs_client *clp, struct hostent *hp)
        new = (nfs_client *) xmalloc(sizeof(*new));
        memcpy(new, clp, sizeof(*new));
        new->m_type = MCL_FQDN;
+       new->m_hostname = NULL;
 
        client_init(new, (char *) hp->h_name, hp);
        client_add(new);
@@ -127,14 +128,11 @@ client_dup(nfs_client *clp, struct hostent *hp)
 static void
 client_init(nfs_client *clp, const char *hname, struct hostent *hp)
 {
-       if (hp) {
-               strncpy(clp->m_hostname, hp->h_name,
-                       sizeof (clp->m_hostname) -  1);
-       } else {
-               strncpy(clp->m_hostname, hname,
-                       sizeof (clp->m_hostname) - 1);
-       }
-       clp->m_hostname[sizeof (clp->m_hostname) - 1] = '\0';
+       xfree(clp->m_hostname);
+       if (hp)
+               clp->m_hostname = xstrdup(hp->h_name);
+       else
+               clp->m_hostname = xstrdup(hname);
 
        clp->m_exported = 0;
        clp->m_count = 0;
@@ -207,6 +205,7 @@ client_freeall(void)
                head = clientlist + i;
                while (*head) {
                        *head = (clp = *head)->m_next;
+                       xfree(clp->m_hostname);
                        xfree(clp);
                }
        }
index 431b5ce7701c0036668d8a61b31367f7b654c44f..a491b1a5a609d693d94def785a4241b1a6f877db 100644 (file)
@@ -32,7 +32,7 @@ enum {
 
 typedef struct mclient {
        struct mclient *        m_next;
-       char                    m_hostname[NFSCLNT_IDMAX+1];
+       char *                  m_hostname;
        int                     m_type;
        int                     m_naddr;
        struct in_addr          m_addrlist[NFSCLNT_ADDRMAX];
index f7fe23dda5ba26b8453e56d99bb56476bd41ec75..950ea20721fe6273821ced59166996fd46d89548 100644 (file)
@@ -93,8 +93,13 @@ auth_authenticate_internal(char *what, struct sockaddr_in *caller,
                *error = unknown_host;
                if (!n)
                        return NULL;
-               strcpy(my_client.m_hostname, *n?n:"DEFAULT");
-               free(n);
+               free(my_client.m_hostname);
+               if (*n) {
+                       my_client.m_hostname = n;
+               } else {
+                       free(n);
+                       my_client.m_hostname = xstrdup("DEFAULT");
+               }
                my_client.m_naddr = 1;
                my_exp.m_client = &my_client;