~ubuntu-branches/ubuntu/precise/curl/precise

« back to all changes in this revision

Viewing changes to lib/nss.c

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2011-11-25 17:30:45 UTC
  • mfrom: (3.4.23 sid)
  • Revision ID: package-import@ubuntu.com-20111125173045-2l3ni88jv16kath0
Tags: 7.22.0-3ubuntu1
* Merge from Debian unstable, remaining changes:
  - Drop dependencies not in main:
    + Build-Depends: Drop stunnel4 and libssh2-1-dev.
    + Drop libssh2-1-dev from libcurl4-openssl-dev's Depends.
  - Add new libcurl3-udeb package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
#include "setup.h"
29
29
 
30
 
#include <string.h>
31
 
#include <stdlib.h>
32
 
#include <ctype.h>
33
30
#ifdef HAVE_SYS_SOCKET_H
34
31
#include <sys/socket.h>
35
32
#endif
95
92
  ptr->type = (_type);                                      \
96
93
  ptr->pValue = (_val);                                     \
97
94
  ptr->ulValueLen = (_len);                                 \
98
 
} while(0)
 
95
} WHILE_FALSE
99
96
 
100
97
#define CERT_NewTempCertificate __CERT_NewTempCertificate
101
98
 
898
895
  }
899
896
}
900
897
 
901
 
static CURLcode init_nss(struct SessionHandle *data)
 
898
static CURLcode nss_init_core(struct SessionHandle *data, const char *cert_dir)
 
899
{
 
900
  if(NSS_IsInitialized())
 
901
    return CURLE_OK;
 
902
 
 
903
  if(cert_dir) {
 
904
    SECStatus rv;
 
905
    const bool use_sql = NSS_VersionCheck("3.12.0");
 
906
    char *certpath = aprintf("%s%s", use_sql ? "sql:" : "", cert_dir);
 
907
    if(!certpath)
 
908
      return CURLE_OUT_OF_MEMORY;
 
909
 
 
910
    infof(data, "Initializing NSS with certpath: %s\n", certpath);
 
911
    rv = NSS_Initialize(certpath, "", "", "", NSS_INIT_READONLY);
 
912
    free(certpath);
 
913
 
 
914
    if(rv == SECSuccess)
 
915
      return CURLE_OK;
 
916
 
 
917
    infof(data, "Unable to initialize NSS database\n");
 
918
  }
 
919
 
 
920
  infof(data, "Initializing NSS with certpath: none\n");
 
921
  if(NSS_NoDB_Init(NULL) == SECSuccess)
 
922
    return CURLE_OK;
 
923
 
 
924
  infof(data, "Unable to initialize NSS\n");
 
925
  return CURLE_SSL_CACERT_BADFILE;
 
926
}
 
927
 
 
928
static CURLcode nss_init(struct SessionHandle *data)
902
929
{
903
930
  char *cert_dir;
904
931
  struct_stat st;
 
932
  CURLcode rv;
 
933
 
905
934
  if(initialized)
906
935
    return CURLE_OK;
907
936
 
922
951
    }
923
952
  }
924
953
 
925
 
  if(!NSS_IsInitialized()) {
926
 
    SECStatus rv;
927
 
    initialized = 1;
928
 
    infof(data, "Initializing NSS with certpath: %s\n",
929
 
          cert_dir ? cert_dir : "none");
930
 
    if(!cert_dir) {
931
 
      rv = NSS_NoDB_Init(NULL);
932
 
    }
933
 
    else {
934
 
      char *certpath =
935
 
        PR_smprintf("%s%s", NSS_VersionCheck("3.12.0") ? "sql:" : "",
936
 
                    cert_dir);
937
 
      rv = NSS_Initialize(certpath, "", "", "", NSS_INIT_READONLY);
938
 
      PR_smprintf_free(certpath);
939
 
    }
940
 
    if(rv != SECSuccess) {
941
 
      infof(data, "Unable to initialize NSS database\n");
942
 
      initialized = 0;
943
 
      return CURLE_SSL_CACERT_BADFILE;
944
 
    }
945
 
  }
 
954
  rv = nss_init_core(data, cert_dir);
 
955
  if(rv)
 
956
    return rv;
946
957
 
947
958
  if(num_enabled_ciphers() == 0)
948
959
    NSS_SetDomesticPolicy();
949
960
 
 
961
  initialized = 1;
950
962
  return CURLE_OK;
951
963
}
952
964
 
981
993
  }
982
994
 
983
995
  PR_Lock(nss_initlock);
984
 
  rv = init_nss(data);
 
996
  rv = nss_init(data);
985
997
  PR_Unlock(nss_initlock);
986
998
  return rv;
987
999
}
1184
1196
 
1185
1197
  /* FIXME. NSS doesn't support multiple databases open at the same time. */
1186
1198
  PR_Lock(nss_initlock);
1187
 
  curlerr = init_nss(conn->data);
 
1199
  curlerr = nss_init(conn->data);
1188
1200
  if(CURLE_OK != curlerr) {
1189
1201
    PR_Unlock(nss_initlock);
1190
1202
    goto error;