Whamcloud - gitweb
LU-5717 ptlrpc: fix deadlock problem of nrs_tbf_timer_cb
[fs/lustre-release.git] / lustre / utils / gss / krb5_util.c
index ab73add..52318a5 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <netdb.h>
+#ifdef HAVE_NETDB_H
+# include <netdb.h>
+#endif
 #include <dirent.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -508,7 +510,7 @@ err_free:
  * might use to perform mount operations.
  *
  * Returns:
- *     0 => Sucess
+ *     0 => Success
  *     nonzero => Error
  */
 static int
@@ -667,7 +669,7 @@ static void
 gssd_set_krb5_ccache_name(char *ccname)
 {
 #ifdef USE_GSS_KRB5_CCACHE_NAME
-       u_int   maj_stat, min_stat;
+       unsigned int    maj_stat, min_stat;
 
        printerr(2, "using gss_krb5_ccache_name to select krb5 ccache %s\n",
                 ccname);
@@ -898,15 +900,15 @@ gssd_get_krb5_machine_cred_list(char ***list)
        struct gssd_k5_kt_princ *ple;
 
        /* Assume failure */
-       retval = -1;
-       *list = (char **) NULL;
+       *list = NULL;
 
        /* Refresh machine credentials */
-       if ((retval = gssd_refresh_krb5_machine_creds())) {
+       retval = gssd_refresh_krb5_machine_creds();
+       if (retval)
                goto out;
-       }
 
-       if ((l = (char **) malloc(listsize * sizeof(char *))) == NULL) {
+       l = malloc(listsize * sizeof(char *));
+       if (l == NULL) {
                retval = ENOMEM;
                goto out;
        }
@@ -914,27 +916,33 @@ gssd_get_krb5_machine_cred_list(char ***list)
        for (ple = gssd_k5_kt_princ_list; ple; ple = ple->next) {
                if (ple->ccname) {
                        if (i + 1 > listsize) {
+                               void *tmp;
+
                                listsize += listinc;
-                               l = (char **)
-                                       realloc(l, listsize * sizeof(char *));
-                               if (l == NULL) {
+                               tmp = realloc(l, listsize * sizeof(char *));
+                               if (tmp == NULL) {
                                        retval = ENOMEM;
-                                       goto out;
+                                       goto out_free;
                                }
+                               l = tmp;
                        }
-                       if ((l[i++] = strdup(ple->ccname)) == NULL) {
+                       l[i] = strdup(ple->ccname);
+                       if (l[i++] == NULL) {
                                retval = ENOMEM;
-                               goto out;
+                               goto out_free;
                        }
                }
        }
        if (i > 0) {
                l[i] = NULL;
                *list = l;
-               retval = 0;
-               goto out;
+               return 0;
        }
-  out:
+out_free:
+       while (i > 0)
+               free(l[i--]);
+       free(l);
+out:
        return retval;
 }
 
@@ -1007,7 +1015,7 @@ gssd_destroy_krb5_machine_creds(void)
 int
 limit_krb5_enctypes(struct rpc_gss_sec *sec, uid_t uid)
 {
-       u_int maj_stat, min_stat;
+       unsigned int maj_stat, min_stat;
        gss_cred_id_t credh;
        gss_OID_set_desc  desired_mechs;
        krb5_enctype enctypes[] = {ENCTYPE_DES_CBC_CRC};