~ubuntu-branches/ubuntu/quantal/curl/quantal-proposed

« back to all changes in this revision

Viewing changes to lib/strerror.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-08-20 13:54:01 UTC
  • mfrom: (3.4.30 sid)
  • Revision ID: package-import@ubuntu.com-20120820135401-5845kg6puoh2jcnh
Tags: 7.27.0-1ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Drop dependencies not in main:
    + Build-Depends: Drop stunnel4 and libssh2-1-dev.
    + Drop libssh2-1-dev from binary package Depends.
  - Add new libcurl3-udeb package.
  - Add new curl-udeb package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 2004 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 2004 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
9
9
 *
10
10
 * This software is licensed as described in the file COPYING, which
11
11
 * you should have received as part of this distribution. The terms
635
635
    strncpy(buf, strerror(err), max);
636
636
  else {
637
637
    if(!get_winsock_error(err, buf, max) &&
638
 
        !FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
 
638
       !FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
639
639
                       LANG_NEUTRAL, buf, (DWORD)max, NULL))
640
640
      snprintf(buf, max, "Unknown error %d (%#x)", err, err);
641
641
  }
781
781
#endif
782
782
}
783
783
#endif  /* USE_LIBIDN */
 
784
 
 
785
#ifdef USE_WINDOWS_SSPI
 
786
const char *Curl_sspi_strerror (struct connectdata *conn, int err)
 
787
{
 
788
#ifndef CURL_DISABLE_VERBOSE_STRINGS
 
789
  char txtbuf[80];
 
790
  char msgbuf[sizeof(conn->syserr_buf)];
 
791
  char *p, *str, *msg = NULL;
 
792
  bool msg_formatted = FALSE;
 
793
  int old_errno;
 
794
#endif
 
795
  const char *txt;
 
796
  char *outbuf;
 
797
  size_t outmax;
 
798
 
 
799
  DEBUGASSERT(conn);
 
800
 
 
801
  outbuf = conn->syserr_buf;
 
802
  outmax = sizeof(conn->syserr_buf)-1;
 
803
  *outbuf = '\0';
 
804
 
 
805
#ifndef CURL_DISABLE_VERBOSE_STRINGS
 
806
 
 
807
  old_errno = ERRNO;
 
808
 
 
809
  switch (err) {
 
810
    case SEC_E_OK:
 
811
      txt = "No error";
 
812
      break;
 
813
    case SEC_E_ALGORITHM_MISMATCH:
 
814
      txt = "SEC_E_ALGORITHM_MISMATCH";
 
815
      break;
 
816
    case SEC_E_BAD_BINDINGS:
 
817
      txt = "SEC_E_BAD_BINDINGS";
 
818
      break;
 
819
    case SEC_E_BAD_PKGID:
 
820
      txt = "SEC_E_BAD_PKGID";
 
821
      break;
 
822
    case SEC_E_BUFFER_TOO_SMALL:
 
823
      txt = "SEC_E_BUFFER_TOO_SMALL";
 
824
      break;
 
825
    case SEC_E_CANNOT_INSTALL:
 
826
      txt = "SEC_E_CANNOT_INSTALL";
 
827
      break;
 
828
    case SEC_E_CANNOT_PACK:
 
829
      txt = "SEC_E_CANNOT_PACK";
 
830
      break;
 
831
    case SEC_E_CERT_EXPIRED:
 
832
      txt = "SEC_E_CERT_EXPIRED";
 
833
      break;
 
834
    case SEC_E_CERT_UNKNOWN:
 
835
      txt = "SEC_E_CERT_UNKNOWN";
 
836
      break;
 
837
    case SEC_E_CERT_WRONG_USAGE:
 
838
      txt = "SEC_E_CERT_WRONG_USAGE";
 
839
      break;
 
840
    case SEC_E_CONTEXT_EXPIRED:
 
841
      txt = "SEC_E_CONTEXT_EXPIRED";
 
842
      break;
 
843
    case SEC_E_CROSSREALM_DELEGATION_FAILURE:
 
844
      txt = "SEC_E_CROSSREALM_DELEGATION_FAILURE";
 
845
      break;
 
846
    case SEC_E_CRYPTO_SYSTEM_INVALID:
 
847
      txt = "SEC_E_CRYPTO_SYSTEM_INVALID";
 
848
      break;
 
849
    case SEC_E_DECRYPT_FAILURE:
 
850
      txt = "SEC_E_DECRYPT_FAILURE";
 
851
      break;
 
852
    case SEC_E_DELEGATION_POLICY:
 
853
      txt = "SEC_E_DELEGATION_POLICY";
 
854
      break;
 
855
    case SEC_E_DELEGATION_REQUIRED:
 
856
      txt = "SEC_E_DELEGATION_REQUIRED";
 
857
      break;
 
858
    case SEC_E_DOWNGRADE_DETECTED:
 
859
      txt = "SEC_E_DOWNGRADE_DETECTED";
 
860
      break;
 
861
    case SEC_E_ENCRYPT_FAILURE:
 
862
      txt = "SEC_E_ENCRYPT_FAILURE";
 
863
      break;
 
864
    case SEC_E_ILLEGAL_MESSAGE:
 
865
      txt = "SEC_E_ILLEGAL_MESSAGE";
 
866
      break;
 
867
    case SEC_E_INCOMPLETE_CREDENTIALS:
 
868
      txt = "SEC_E_INCOMPLETE_CREDENTIALS";
 
869
      break;
 
870
    case SEC_E_INCOMPLETE_MESSAGE:
 
871
      txt = "SEC_E_INCOMPLETE_MESSAGE";
 
872
      break;
 
873
    case SEC_E_INSUFFICIENT_MEMORY:
 
874
      txt = "SEC_E_INSUFFICIENT_MEMORY";
 
875
      break;
 
876
    case SEC_E_INTERNAL_ERROR:
 
877
      txt = "SEC_E_INTERNAL_ERROR";
 
878
      break;
 
879
    case SEC_E_INVALID_HANDLE:
 
880
      txt = "SEC_E_INVALID_HANDLE";
 
881
      break;
 
882
    case SEC_E_INVALID_PARAMETER:
 
883
      txt = "SEC_E_INVALID_PARAMETER";
 
884
      break;
 
885
    case SEC_E_INVALID_TOKEN:
 
886
      txt = "SEC_E_INVALID_TOKEN";
 
887
      break;
 
888
    case SEC_E_ISSUING_CA_UNTRUSTED:
 
889
      txt = "SEC_E_ISSUING_CA_UNTRUSTED";
 
890
      break;
 
891
    case SEC_E_ISSUING_CA_UNTRUSTED_KDC:
 
892
      txt = "SEC_E_ISSUING_CA_UNTRUSTED_KDC";
 
893
      break;
 
894
    case SEC_E_KDC_CERT_EXPIRED:
 
895
      txt = "SEC_E_KDC_CERT_EXPIRED";
 
896
      break;
 
897
    case SEC_E_KDC_CERT_REVOKED:
 
898
      txt = "SEC_E_KDC_CERT_REVOKED";
 
899
      break;
 
900
    case SEC_E_KDC_INVALID_REQUEST:
 
901
      txt = "SEC_E_KDC_INVALID_REQUEST";
 
902
      break;
 
903
    case SEC_E_KDC_UNABLE_TO_REFER:
 
904
      txt = "SEC_E_KDC_UNABLE_TO_REFER";
 
905
      break;
 
906
    case SEC_E_KDC_UNKNOWN_ETYPE:
 
907
      txt = "SEC_E_KDC_UNKNOWN_ETYPE";
 
908
      break;
 
909
    case SEC_E_LOGON_DENIED:
 
910
      txt = "SEC_E_LOGON_DENIED";
 
911
      break;
 
912
    case SEC_E_MAX_REFERRALS_EXCEEDED:
 
913
      txt = "SEC_E_MAX_REFERRALS_EXCEEDED";
 
914
      break;
 
915
    case SEC_E_MESSAGE_ALTERED:
 
916
      txt = "SEC_E_MESSAGE_ALTERED";
 
917
      break;
 
918
    case SEC_E_MULTIPLE_ACCOUNTS:
 
919
      txt = "SEC_E_MULTIPLE_ACCOUNTS";
 
920
      break;
 
921
    case SEC_E_MUST_BE_KDC:
 
922
      txt = "SEC_E_MUST_BE_KDC";
 
923
      break;
 
924
    case SEC_E_NOT_OWNER:
 
925
      txt = "SEC_E_NOT_OWNER";
 
926
      break;
 
927
    case SEC_E_NO_AUTHENTICATING_AUTHORITY:
 
928
      txt = "SEC_E_NO_AUTHENTICATING_AUTHORITY";
 
929
      break;
 
930
    case SEC_E_NO_CREDENTIALS:
 
931
      txt = "SEC_E_NO_CREDENTIALS";
 
932
      break;
 
933
    case SEC_E_NO_IMPERSONATION:
 
934
      txt = "SEC_E_NO_IMPERSONATION";
 
935
      break;
 
936
    case SEC_E_NO_IP_ADDRESSES:
 
937
      txt = "SEC_E_NO_IP_ADDRESSES";
 
938
      break;
 
939
    case SEC_E_NO_KERB_KEY:
 
940
      txt = "SEC_E_NO_KERB_KEY";
 
941
      break;
 
942
    case SEC_E_NO_PA_DATA:
 
943
      txt = "SEC_E_NO_PA_DATA";
 
944
      break;
 
945
    case SEC_E_NO_S4U_PROT_SUPPORT:
 
946
      txt = "SEC_E_NO_S4U_PROT_SUPPORT";
 
947
      break;
 
948
    case SEC_E_NO_TGT_REPLY:
 
949
      txt = "SEC_E_NO_TGT_REPLY";
 
950
      break;
 
951
    case SEC_E_OUT_OF_SEQUENCE:
 
952
      txt = "SEC_E_OUT_OF_SEQUENCE";
 
953
      break;
 
954
    case SEC_E_PKINIT_CLIENT_FAILURE:
 
955
      txt = "SEC_E_PKINIT_CLIENT_FAILURE";
 
956
      break;
 
957
    case SEC_E_PKINIT_NAME_MISMATCH:
 
958
      txt = "SEC_E_PKINIT_NAME_MISMATCH";
 
959
      break;
 
960
    case SEC_E_POLICY_NLTM_ONLY:
 
961
      txt = "SEC_E_POLICY_NLTM_ONLY";
 
962
      break;
 
963
    case SEC_E_QOP_NOT_SUPPORTED:
 
964
      txt = "SEC_E_QOP_NOT_SUPPORTED";
 
965
      break;
 
966
    case SEC_E_REVOCATION_OFFLINE_C:
 
967
      txt = "SEC_E_REVOCATION_OFFLINE_C";
 
968
      break;
 
969
    case SEC_E_REVOCATION_OFFLINE_KDC:
 
970
      txt = "SEC_E_REVOCATION_OFFLINE_KDC";
 
971
      break;
 
972
    case SEC_E_SECPKG_NOT_FOUND:
 
973
      txt = "SEC_E_SECPKG_NOT_FOUND";
 
974
      break;
 
975
    case SEC_E_SECURITY_QOS_FAILED:
 
976
      txt = "SEC_E_SECURITY_QOS_FAILED";
 
977
      break;
 
978
    case SEC_E_SHUTDOWN_IN_PROGRESS:
 
979
      txt = "SEC_E_SHUTDOWN_IN_PROGRESS";
 
980
      break;
 
981
    case SEC_E_SMARTCARD_CERT_EXPIRED:
 
982
      txt = "SEC_E_SMARTCARD_CERT_EXPIRED";
 
983
      break;
 
984
    case SEC_E_SMARTCARD_CERT_REVOKED:
 
985
      txt = "SEC_E_SMARTCARD_CERT_REVOKED";
 
986
      break;
 
987
    case SEC_E_SMARTCARD_LOGON_REQUIRED:
 
988
      txt = "SEC_E_SMARTCARD_LOGON_REQUIRED";
 
989
      break;
 
990
    case SEC_E_STRONG_CRYPTO_NOT_SUPPORTED:
 
991
      txt = "SEC_E_STRONG_CRYPTO_NOT_SUPPORTED";
 
992
      break;
 
993
    case SEC_E_TARGET_UNKNOWN:
 
994
      txt = "SEC_E_TARGET_UNKNOWN";
 
995
      break;
 
996
    case SEC_E_TIME_SKEW:
 
997
      txt = "SEC_E_TIME_SKEW";
 
998
      break;
 
999
    case SEC_E_TOO_MANY_PRINCIPALS:
 
1000
      txt = "SEC_E_TOO_MANY_PRINCIPALS";
 
1001
      break;
 
1002
    case SEC_E_UNFINISHED_CONTEXT_DELETED:
 
1003
      txt = "SEC_E_UNFINISHED_CONTEXT_DELETED";
 
1004
      break;
 
1005
    case SEC_E_UNKNOWN_CREDENTIALS:
 
1006
      txt = "SEC_E_UNKNOWN_CREDENTIALS";
 
1007
      break;
 
1008
    case SEC_E_UNSUPPORTED_FUNCTION:
 
1009
      txt = "SEC_E_UNSUPPORTED_FUNCTION";
 
1010
      break;
 
1011
    case SEC_E_UNSUPPORTED_PREAUTH:
 
1012
      txt = "SEC_E_UNSUPPORTED_PREAUTH";
 
1013
      break;
 
1014
    case SEC_E_UNTRUSTED_ROOT:
 
1015
      txt = "SEC_E_UNTRUSTED_ROOT";
 
1016
      break;
 
1017
    case SEC_E_WRONG_CREDENTIAL_HANDLE:
 
1018
      txt = "SEC_E_WRONG_CREDENTIAL_HANDLE";
 
1019
      break;
 
1020
    case SEC_E_WRONG_PRINCIPAL:
 
1021
      txt = "SEC_E_WRONG_PRINCIPAL";
 
1022
      break;
 
1023
    case SEC_I_COMPLETE_AND_CONTINUE:
 
1024
      txt = "SEC_I_COMPLETE_AND_CONTINUE";
 
1025
      break;
 
1026
    case SEC_I_COMPLETE_NEEDED:
 
1027
      txt = "SEC_I_COMPLETE_NEEDED";
 
1028
      break;
 
1029
    case SEC_I_CONTEXT_EXPIRED:
 
1030
      txt = "SEC_I_CONTEXT_EXPIRED";
 
1031
      break;
 
1032
    case SEC_I_CONTINUE_NEEDED:
 
1033
      txt = "SEC_I_CONTINUE_NEEDED";
 
1034
      break;
 
1035
    case SEC_I_INCOMPLETE_CREDENTIALS:
 
1036
      txt = "SEC_I_INCOMPLETE_CREDENTIALS";
 
1037
      break;
 
1038
    case SEC_I_LOCAL_LOGON:
 
1039
      txt = "SEC_I_LOCAL_LOGON";
 
1040
      break;
 
1041
    case SEC_I_NO_LSA_CONTEXT:
 
1042
      txt = "SEC_I_NO_LSA_CONTEXT";
 
1043
      break;
 
1044
    case SEC_I_RENEGOTIATE:
 
1045
      txt = "SEC_I_RENEGOTIATE";
 
1046
      break;
 
1047
    case SEC_I_SIGNATURE_NEEDED:
 
1048
      txt = "SEC_I_SIGNATURE_NEEDED";
 
1049
      break;
 
1050
    default:
 
1051
      txt = "Unknown error";
 
1052
  }
 
1053
 
 
1054
  if(err == SEC_E_OK)
 
1055
    strncpy(outbuf, txt, outmax);
 
1056
  else {
 
1057
    str = txtbuf;
 
1058
    snprintf(txtbuf, sizeof(txtbuf), "%s (0x%04X%04X)",
 
1059
             txt, (err >> 16) & 0xffff, err & 0xffff);
 
1060
    txtbuf[sizeof(txtbuf)-1] = '\0';
 
1061
 
 
1062
#ifdef _WIN32_WCE
 
1063
    {
 
1064
      wchar_t wbuf[256];
 
1065
      wbuf[0] = L'\0';
 
1066
 
 
1067
      if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
 
1068
                       FORMAT_MESSAGE_IGNORE_INSERTS,
 
1069
                       NULL, err, LANG_NEUTRAL,
 
1070
                       wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL)) {
 
1071
        wcstombs(msgbuf,wbuf,sizeof(msgbuf)-1);
 
1072
        msg_formatted = TRUE;
 
1073
      }
 
1074
    }
 
1075
#else
 
1076
    if(FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
 
1077
                      FORMAT_MESSAGE_IGNORE_INSERTS,
 
1078
                      NULL, err, LANG_NEUTRAL,
 
1079
                      msgbuf, sizeof(msgbuf)-1, NULL)) {
 
1080
      msg_formatted = TRUE;
 
1081
    }
 
1082
#endif
 
1083
    if(msg_formatted) {
 
1084
      msgbuf[sizeof(msgbuf)-1] = '\0';
 
1085
      /* strip trailing '\r\n' or '\n' */
 
1086
      if((p = strrchr(msgbuf,'\n')) != NULL && (p - msgbuf) >= 2)
 
1087
         *p = '\0';
 
1088
      if((p = strrchr(msgbuf,'\r')) != NULL && (p - msgbuf) >= 1)
 
1089
         *p = '\0';
 
1090
      msg = msgbuf;
 
1091
    }
 
1092
    if(msg)
 
1093
      snprintf(outbuf, outmax, "%s - %s", str, msg);
 
1094
    else
 
1095
      strncpy(outbuf, str, outmax);
 
1096
  }
 
1097
 
 
1098
  if(old_errno != ERRNO)
 
1099
    SET_ERRNO(old_errno);
 
1100
 
 
1101
#else
 
1102
 
 
1103
  if(err == SEC_E_OK)
 
1104
    txt = "No error";
 
1105
  else
 
1106
    txt = "Error";
 
1107
 
 
1108
  strncpy(outbuf, txt, outmax);
 
1109
 
 
1110
#endif
 
1111
 
 
1112
  outbuf[outmax] = '\0';
 
1113
 
 
1114
  return outbuf;
 
1115
}
 
1116
#endif /* USE_WINDOWS_SSPI */