diff options
author | Michael R Sweet <michael.r.sweet@gmail.com> | 2019-01-18 12:11:34 -0500 |
---|---|---|
committer | Michael R Sweet <michael.r.sweet@gmail.com> | 2019-01-18 12:11:34 -0500 |
commit | 588c22056a599c944f12f84b06244e6cd93ba0a2 (patch) | |
tree | 0f2d42375bd40df39da9643e74fc85c6dcf850c3 | |
parent | 690b9231511167046eb654d5cb69471e42e92d0d (diff) | |
download | cups-588c22056a599c944f12f84b06244e6cd93ba0a2.tar.gz |
Fix iOS libcups builds (rdar://47386169)
-rw-r--r-- | cups/tls-darwin.c | 8 | ||||
-rw-r--r-- | cups/usersys.c | 121 | ||||
-rw-r--r-- | xcode/CUPS.xcodeproj/project.pbxproj | 2 |
3 files changed, 105 insertions, 26 deletions
diff --git a/cups/tls-darwin.c b/cups/tls-darwin.c index 75996d2e6..d0b65f1eb 100644 --- a/cups/tls-darwin.c +++ b/cups/tls-darwin.c @@ -849,8 +849,10 @@ httpCredentialsString( * issuer name is, um, "interesting"... */ - CFStringRef cf_string; /* CF string */ +# if !TARGET_OS_IOS CFDictionaryRef cf_dict; /* Dictionary for certificate */ +# endif /* !TARGET_OS_IOS */ + CFStringRef cf_string; /* CF string */ char commonName[256],/* Common name associated with cert */ issuer[256], /* Issuer name */ sigalg[256]; /* Signature algorithm */ @@ -870,6 +872,7 @@ httpCredentialsString( strlcpy(issuer, "unknown", sizeof(issuer)); strlcpy(sigalg, "UnknownSignature", sizeof(sigalg)); +# if !TARGET_OS_IOS if ((cf_dict = SecCertificateCopyValues(secCert, NULL, NULL)) != NULL) { CFDictionaryRef cf_issuer = CFDictionaryGetValue(cf_dict, kSecOIDX509V1IssuerName); @@ -916,6 +919,7 @@ httpCredentialsString( CFRelease(cf_dict); } +# endif /* !TARGET_OS_IOS */ expiration = (time_t)(SecCertificateNotValidAfter(secCert) + kCFAbsoluteTimeIntervalSince1970); @@ -1999,6 +2003,8 @@ http_cdsa_copy_server( return (certificates); #else + (void)common_name; + if (!tls_selfsigned) return (NULL); diff --git a/cups/usersys.c b/cups/usersys.c index c4408ac73..b56b892b4 100644 --- a/cups/usersys.c +++ b/cups/usersys.c @@ -22,6 +22,9 @@ # include <termios.h> # include <sys/utsname.h> #endif /* _WIN32 */ +#ifdef __APPLE__ +# include <sys/sysctl.h> +#endif /* __APPLE__ */ /* @@ -29,14 +32,24 @@ */ #ifdef __APPLE__ -# define kCUPSPrintingPrefs CFSTR("org.cups.PrintingPrefs") -# define kAllowAnyRootKey CFSTR("AllowAnyRoot") -# define kAllowExpiredCertsKey CFSTR("AllowExpiredCerts") -# define kEncryptionKey CFSTR("Encryption") -# define kGSSServiceNameKey CFSTR("GSSServiceName") -# define kSSLOptionsKey CFSTR("SSLOptions") -# define kTrustOnFirstUseKey CFSTR("TrustOnFirstUse") -# define kValidateCertsKey CFSTR("ValidateCerts") +# if TARGET_OS_IOS +# define kCUPSPrintingPrefs CFSTR(".GlobalPreferences") +# define kPREFIX "AirPrint" +# else +# define kCUPSPrintingPrefs CFSTR("org.cups.PrintingPrefs") +# define kPREFIX "" +# endif /* TARGET_OS_IOS */ +# define kAllowAnyRootKey CFSTR(kPREFIX "AllowAnyRoot") +# define kAllowExpiredCertsKey CFSTR(kPREFIX "AllowExpiredCerts") +# define kEncryptionKey CFSTR(kPREFIX "Encryption") +# define kGSSServiceNameKey CFSTR(kPREFIX "GSSServiceName") +# define kSSLOptionsKey CFSTR(kPREFIX "SSLOptions") +# define kTrustOnFirstUseKey CFSTR(kPREFIX "TrustOnFirstUse") +# define kValidateCertsKey CFSTR(kPREFIX "ValidateCerts") +/* Deprecated */ +# define kAllowRC4 CFSTR(kPREFIX "AllowRC4") +# define kAllowSSL3 CFSTR(kPREFIX "AllowSSL3") +# define kAllowDH CFSTR(kPREFIX "AllowDH") #endif /* __APPLE__ */ #define _CUPS_PASSCHAR '*' /* Character that is echoed for password */ @@ -488,6 +501,11 @@ cupsSetUserAgent(const char *user_agent)/* I - User-Agent string or @code NULL@ #ifdef _WIN32 SYSTEM_INFO sysinfo; /* System information */ OSVERSIONINFOA version; /* OS version info */ + const char *machine; /* Hardware/machine name */ +#elif defined(__APPLE__) + struct utsname name; /* uname info */ + char version[256]; /* macOS/iOS version */ + size_t len; /* Length of value */ #else struct utsname name; /* uname info */ #endif /* _WIN32 */ @@ -500,29 +518,66 @@ cupsSetUserAgent(const char *user_agent)/* I - User-Agent string or @code NULL@ } #ifdef _WIN32 + /* + * Gather Windows version information for the User-Agent string... + */ + version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionExA(&version); GetNativeSystemInfo(&sysinfo); - snprintf(cg->user_agent, sizeof(cg->user_agent), - CUPS_MINIMAL " (Windows %d.%d; %s) IPP/2.0", - version.dwMajorVersion, version.dwMinorVersion, - sysinfo.wProcessorArchitecture - == PROCESSOR_ARCHITECTURE_AMD64 ? "amd64" : - sysinfo.wProcessorArchitecture - == PROCESSOR_ARCHITECTURE_ARM ? "arm" : - sysinfo.wProcessorArchitecture - == PROCESSOR_ARCHITECTURE_IA64 ? "ia64" : - sysinfo.wProcessorArchitecture - == PROCESSOR_ARCHITECTURE_INTEL ? "intel" : - "unknown"); + switch (sysinfo.wProcessorArchitecture) + { + case PROCESSOR_ARCHITECTURE_AMD64 : + machine = "amd64"; + break; + + case PROCESSOR_ARCHITECTURE_ARM : + machine = "arm"; + break; + + case PROCESSOR_ARCHITECTURE_IA64 : + machine = "ia64"; + break; + + case PROCESSOR_ARCHITECTURE_INTEL : + machine = "intel"; + break; + + default : + machine = "unknown"; + break; + } + + snprintf(cg->user_agent, sizeof(cg->user_agent), CUPS_MINIMAL " (Windows %d.%d; %s) IPP/2.0", version.dwMajorVersion, version.dwMinorVersion, machine); + +#elif defined(__APPLE__) + /* + * Gather macOS/iOS version information for the User-Agent string... + */ + + uname(&name); + + len = sizeof(version) - 1; + if (!sysctlbyname("kern.osproductversion", version, &len, NULL, 0)) + version[len] = '\0'; + else + strlcpy(version, "unknown", sizeof(version)); + +# if TARGET_OS_IOS + snprintf(cg->user_agent, sizeof(cg->user_agent), CUPS_MINIMAL " (iOS %s; %s) IPP/2.0", version, name.machine); +# else + snprintf(cg->user_agent, sizeof(cg->user_agent), CUPS_MINIMAL " (macOS %s; %s) IPP/2.0", version, name.machine); +# endif /* TARGET_OS_IOS */ #else + /* + * Gather generic UNIX version information for the User-Agent string... + */ + uname(&name); - snprintf(cg->user_agent, sizeof(cg->user_agent), - CUPS_MINIMAL " (%s %s; %s) IPP/2.0", - name.sysname, name.release, name.machine); + snprintf(cg->user_agent, sizeof(cg->user_agent), CUPS_MINIMAL " (%s %s; %s) IPP/2.0", name.sysname, name.release, name.machine); #endif /* _WIN32 */ } @@ -1161,6 +1216,10 @@ cups_init_client_conf( memset(cc, 0, sizeof(_cups_client_conf_t)); +#if TARGET_OS_IOS + cups_set_user(cc, "mobile"); +#endif /* TARGET_OS_IOS */ + #ifdef HAVE_SSL cc->ssl_min_version = _HTTP_TLS_1_0; cc->ssl_max_version = _HTTP_TLS_MAX; @@ -1190,7 +1249,23 @@ cups_init_client_conf( cups_set_encryption(cc, sval); if (cups_apple_get_string(kSSLOptionsKey, sval, sizeof(sval))) + { cups_set_ssl_options(cc, sval); + } + else + { + sval[0] = '\0'; + + if (cups_apple_get_boolean(kAllowRC4, &bval) && bval) + strlcat(sval, " AllowRC4", sizeof(sval)); + if (cups_apple_get_boolean(kAllowSSL3, &bval) && bval) + strlcat(sval, " AllowSSL3", sizeof(sval)); + if (cups_apple_get_boolean(kAllowDH, &bval) && bval) + strlcat(sval, " AllowDH", sizeof(sval)); + + if (sval[0]) + cups_set_ssl_options(cc, sval); + } if (cups_apple_get_boolean(kTrustOnFirstUseKey, &bval)) cc->trust_first = bval; diff --git a/xcode/CUPS.xcodeproj/project.pbxproj b/xcode/CUPS.xcodeproj/project.pbxproj index 4ef98fd5f..5ce56507e 100644 --- a/xcode/CUPS.xcodeproj/project.pbxproj +++ b/xcode/CUPS.xcodeproj/project.pbxproj @@ -815,7 +815,6 @@ 7253C45A216E981900494ADD /* raster-interpret.c in Sources */ = {isa = PBXBuildFile; fileRef = 72F75A6A1336FA8A004BB496 /* raster-interpret.c */; }; 7253C45B216E981A00494ADD /* raster-interpret.c in Sources */ = {isa = PBXBuildFile; fileRef = 72F75A6A1336FA8A004BB496 /* raster-interpret.c */; }; 7253C45E216ED51500494ADD /* raster-interstub.c in Sources */ = {isa = PBXBuildFile; fileRef = 7253C45C216ED51400494ADD /* raster-interstub.c */; }; - 7253C45F216ED51500494ADD /* raster-interstub.c in Sources */ = {isa = PBXBuildFile; fileRef = 7253C45C216ED51400494ADD /* raster-interstub.c */; }; 7253C460216ED51500494ADD /* raster-interstub.c in Sources */ = {isa = PBXBuildFile; fileRef = 7253C45C216ED51400494ADD /* raster-interstub.c */; }; 7253C461216ED51500494ADD /* raster-interstub.c in Sources */ = {isa = PBXBuildFile; fileRef = 7253C45C216ED51400494ADD /* raster-interstub.c */; }; 7253C462216ED51500494ADD /* raster-interstub.c in Sources */ = {isa = PBXBuildFile; fileRef = 7253C45C216ED51400494ADD /* raster-interstub.c */; }; @@ -7353,7 +7352,6 @@ 270696101CADF3E200FFE5FB /* globals.c in Sources */, 270696111CADF3E200FFE5FB /* http-addr.c in Sources */, 270696121CADF3E200FFE5FB /* http-addrlist.c in Sources */, - 7253C45F216ED51500494ADD /* raster-interstub.c in Sources */, 270696131CADF3E200FFE5FB /* http-support.c in Sources */, 7253C464216ED51500494ADD /* raster-stubs.c in Sources */, 270696141CADF3E200FFE5FB /* http.c in Sources */, |