void UHttpPlugIn::handlerDelete() { U_TRACE_NO_PARAM(0, "UHttpPlugIn::handlerDelete()") U_INTERNAL_DUMP("UEventFd::fd = %d", UEventFd::fd) UEventFd::fd = -1; }
UString USOAPParser::processMessage(const UString& msg, URPCObject& object, bool& bContainsFault) { U_TRACE(0, "USOAPParser::processMessage(%V,%p,%p,%b)", msg.rep, &object, &bContainsFault) U_INTERNAL_ASSERT(msg) UString retval; clearData(); if (U_STRING_FIND(msg, 0, "http://schemas.xmlsoap.org/soap/envelope/") != U_NOT_FOUND) { zero(); bContainsFault = true; (void) retval.assign(U_CONSTANT_TO_PARAM("<?xml version=\"1.0\" ?>" "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">" "<env:Header>" "<env:Upgrade>" "<env:SupportedEnvelope qname=\"ns1:Envelope\" xmlns:ns1=\"http://www.w3.org/2003/05/soap-envelope\"/>" "</env:Upgrade>" "</env:Header>" "<env:Body>" "<env:Fault>" "<faultcode>env:VersionMismatch</faultcode>" "<faultstring>Version Mismatch</faultstring>" "</env:Fault>" "</env:Body>" "</env:Envelope>")); } else if (parse(msg)) { U_ASSERT_EQUALS(envelope.methodName.equal(U_CONSTANT_TO_PARAM("Fault")), false) retval = object.processMessage(envelope, bContainsFault); } else { int line = ::XML_GetCurrentLineNumber(m_parser), coln = ::XML_GetCurrentColumnNumber(m_parser); object.setFailed(); URPCMethod::pFault->getFaultReason() = UXMLParser::getErrorMessage(); U_INTERNAL_DUMP("UXMLParser: %V (%d,%d) ", URPCMethod::pFault->getFaultReason().rep, line, coln) URPCMethod::pFault->setDetail("The fault occurred near position (line: %d col: %d) within the message", line, coln); bContainsFault = true; retval = URPCMethod::encoder->encodeFault(URPCMethod::pFault); } U_RETURN_STRING(retval); }
static VALUE URUBY_io_rewind(VALUE obj, VALUE args) { U_TRACE(0, "URUBY_io_rewind(%llu,%llu)", obj, args) post_readline_pos = UClientImage_Base::body->data(); post_readline_watermark = post_readline_pos + UClientImage_Base::body->size(); U_INTERNAL_DUMP("post_readline_pos = %p post_readline_watermark = %p", post_readline_pos, post_readline_watermark) U_RETURN(Qnil); }
int U_EXPORT main (int argc, char* argv[]) { U_ULIB_INIT(argv); U_TRACE(5,"main(%d)",argc) U_ASSERT_EQUALS( UServices::dosMatchWithOR(U_CONSTANT_TO_PARAM("www.sito1.com"), U_CONSTANT_TO_PARAM("SSI|benchmark|www.sito1.com|www.sito2.com"), FNM_INVERT), false) UString buffer(2000); u_base64_max_columns = 72; UBase64::encode(U_CONSTANT_TO_PARAM(TESTOA), buffer); U_INTERNAL_DUMP("buffer = %#.*S", U_STRING_TO_TRACE(buffer)) U_ASSERT( buffer == U_STRING_FROM_CONSTANT(TESTOB) ) UBase64::decode( U_CONSTANT_TO_PARAM(TESTOB), buffer); U_ASSERT( buffer == U_STRING_FROM_CONSTANT(TESTOA) ) UString cmd, result1, result2; int fd_stderr = U_SYSCALL(open, "%S,%d", "err/services.err", O_WRONLY); cmd = U_STRING_FROM_CONSTANT("ls test_services.cpp"); result1 = UCommand::outputCommand(cmd); // U_ASSERT( result1 == U_STRING_FROM_CONSTANT("test_services.cpp\n") ) buffer = UServices::getUUID(); U_INTERNAL_DUMP("buffer = %#.*S", U_STRING_TO_TRACE(buffer)) cmd = U_STRING_FROM_CONSTANT("cat test_services.cpp"); result2 = UCommand::outputCommand(cmd, 0, -1, fd_stderr); U_ASSERT( result2.empty() == false ) cout.write(result2.data(), result2.size()); }
static VALUE URUBY_io_new(VALUE _class) { U_TRACE(0, "URUBY_io_new(%llu)", _class) VALUE self = Data_Wrap_Struct(_class, U_NULLPTR, U_NULLPTR, U_NULLPTR); U_INTERNAL_DUMP("self = %llu", self) U_SYSCALL_VOID(rb_obj_call_init, "%llu,%d,%p", self, 0, U_NULLPTR); U_RETURN(self); }
UClient_Base::UClient_Base(UFileConfig* cfg) : response(U_CAPACITY), buffer(U_CAPACITY), host_port(100U) { U_TRACE_REGISTER_OBJECT(0, UClient_Base, "%p", cfg) u_init_ulib_hostname(); U_INTERNAL_DUMP("u_hostname(%u) = %.*S", u_hostname_len, u_hostname_len, u_hostname) u_init_ulib_username(); U_INTERNAL_DUMP("u_user_name(%u) = %.*S", u_user_name_len, u_user_name_len, u_user_name) timeoutMS = U_TIMEOUT_MS; if (cfg) loadConfigParam(*cfg); else { bIPv6 = false; port = verify_mode = 0; } }
void run(int argc, char* argv[], char* env[]) { U_TRACE(5, "Application::run(%d,%p,%p)", argc, argv, env) Action::run(argc, argv, env); // read stdin and scanf Action::processInputData(2); // -------------------------------------------------------------------------------------------------------------- // configuration parameters // -------------------------------------------------------------------------------------------------------------- // SUBJECT_TEMPLATE scanf form to extract data from mail header Subject: // SEARCH_ENGINE_FOLDER_SEARCH_URL url to do query to search engine // -------------------------------------------------------------------------------------------------------------- UString subj_tmpl = cfg[U_STRING_FROM_CONSTANT("SUBJECT_TEMPLATE")], url = cfg[U_STRING_FROM_CONSTANT("SEARCH_ENGINE_FOLDER_SEARCH_URL")]; uint32_t subject = U_STRING_FIND(request, 0, "Subject: "); if (subject == U_NOT_FOUND) U_ERROR("cannot find mail header subject on input data..."); // scanf mail header Subject: from request // ---------------------------------------------------------------------------------------------------------------------------- // "Subject: %*[^"]\"%[^"]\", %*[^"]\"%[^"]\", %*[^"]\"%[^"]\"" // ---------------------------------------------------------------------------------------------------------------------------- // Subject: Re: TUnwired processo di registrazione utente residenziale con CPE: // notifica produzione CPE cliente "workflow test", indirizzo installazione "Via Volturno, 12 50100 Firenze (FI)", // UID "37723e2d-d052-4c13-a1e9-134563eb9666" // ---------------------------------------------------------------------------------------------------------------------------- int n = U_SYSCALL(sscanf, "%S,%S,%p,%p,%p,%p", request.c_pointer(subject), subj_tmpl.data(), customer, installation, uid); if (n != 3) U_ERROR("scanf error on mail header subject..."); U_INTERNAL_DUMP("sscanf() customer = %S installation = %S uid = %S", customer, installation, uid) // query to Search Engine UString body(10U + u__strlen(uid)); body.snprintf("query=%s", uid); bool ok = Action::sendHttpPostRequest(url, body, "application/x-www-form-urlencoded", "1\n"); Action::writeToSTDOUT(ok, ok); }
void UBase64::encodeUrl(const char* s, uint32_t n, UString& buffer) { U_TRACE(0, "UBase64::encodeUrl(%.*S,%u,%.*S)", n, s, n, U_STRING_TO_TRACE(buffer)) #ifdef DEBUG uint32_t length = ((n + 2) / 3) * 4, num_lines = (u_base64_max_columns ? length / u_base64_max_columns + 1 : 0); U_INTERNAL_DUMP("buffer.capacity() = %u length = %u num_lines = %u", buffer.capacity(), length, num_lines) U_ASSERT(buffer.capacity() >= length + num_lines + 1) #endif uint32_t pos = u_base64url_encode((const unsigned char*)s, n, (unsigned char*)buffer.data()); buffer.size_adjust(pos); }
bool UProcess::fork() { U_TRACE_NO_PARAM(1, "UProcess::fork()") U_CHECK_MEMORY _pid = U_FORK(); if (child()) u_setPid(); running = (_pid != -1); U_INTERNAL_DUMP("%P running = %b", running) U_RETURN(running); }
UShibTarget::UShibTarget() { U_TRACE_NO_PARAM(5, "UShibTarget::UShibTarget()") m_dc = create_shib_dir_config(); // Initialize the request from the parsed URL // protocol == http, https, etc // hostname == server name // port == server port // uri == resource path // method == GET, POST, etc. U_INTERNAL_DUMP("protocol = %S hostname = %S port = %d uri = %S content_type = %S remote_addr = %S method = %.*S", protocol, hostname, port, uri, content_type, remote_addr, U_HTTP_METHOD_TO_TRACE) ShibTarget::init(protocol, hostname, port, uri, content_type, remote_addr, U_http_method_list[U_http_method_num].name); }
void UThread::yield() { U_TRACE_NO_PARAM(1, "UThread::yield()") // Yields the current thread's CPU time slice to allow another thread to begin immediate execution U_INTERNAL_DUMP("cancel = %d", cancel) #ifdef HAVE_PTHREAD_CANCEL U_SYSCALL_VOID_NO_PARAM(pthread_testcancel); #elif !defined(_MSWINDOWS_) && !defined(__UNIKERNEL__) sigset_t old = 0; if (cancel != cancelInitial && cancel != cancelDisabled) { sigset_t scancel; # ifdef sigemptyset sigemptyset(&scancel); # else (void) U_SYSCALL(sigemptyset, "%p", &scancel); # endif # ifdef sigaddset sigaddset(&scancel, U_SIG_THREAD_CANCEL); # else (void) U_SYSCALL(sigaddset, "%p,%d", &scancel, U_SIG_THREAD_CANCEL); # endif (void) U_SYSCALL(pthread_sigmask, "%d,%p,%p", SIG_UNBLOCK, &scancel, &old); } #endif #ifdef HAVE_PTHREAD_YIELD (void) U_SYSCALL_NO_PARAM(pthread_yield); #endif #if !defined(HAVE_PTHREAD_CANCEL) && !defined(_MSWINDOWS_) && !defined(__UNIKERNEL__) if (old) (void) U_SYSCALL(pthread_sigmask, "%d,%p,%p", SIG_SETMASK, &old, 0); #endif }
bool UBase64::decodeAll(const char* s, uint32_t n, UString& buffer) { U_TRACE(0, "UBase64::decodeAll(%.*S,%u,%.*S)", n, s, n, U_STRING_TO_TRACE(buffer)) uint32_t pos = u_base64all_decode(s, n, (unsigned char*)buffer.data()); buffer.size_adjust(pos); U_INTERNAL_DUMP("u_base64_errors = %u buffer(%u) = %#.*S", u_base64_errors, buffer.size(), U_STRING_TO_TRACE(buffer)) if (pos > 0 && u_base64_errors == 0) { U_RETURN(true); } U_INTERNAL_DUMP("buffer(%u) = %#.*S", buffer.size(), U_STRING_TO_TRACE(buffer)) U_RETURN(false); }
UString getOptionValue(const char* param, const char* tag) { U_TRACE(5, "Application::getOptionValue(%S,%S)", param, tag) UString result; if (param && *param) result = param; else { UString tmp(100U); U_INTERNAL_DUMP("xades_c = %b", xades_c) tmp.snprintf(U_CONSTANT_TO_PARAM("XAdES-%s.%s"), (xades_c ? "C" : "BES"), tag); result = cfg[tmp]; } U_RETURN_STRING(result); }
void run(int argc, char* argv[], char* env[]) { U_TRACE(5, "Application::run(%d,%p,%p)", argc, argv, env) UApplication::run(argc, argv, env); // LDAP attribute for devices // manage arg operation // manage file configuration // manage options // login to LDAP # include "common1.cpp" if (UApplication::isOptions()) { value = opt['b']; if (value.empty() == false) DN_filter = value; } // get filter attribute from LDAP int i, n = ldap.search(DN_filter.c_str(), LDAP_SCOPE_BASE, (char**)filter_attr_name); if (n != 1) U_ERROR("cannot get filter attribute from LDAP..."); ULDAPEntry filter_entry(FILTER_NUM_ATTR, filter_attr_name); ldap.get(filter_entry); // dato filtro avvio ricerca policy usando valore attributo filtro <tnetLrpFilterRule> const char* filtro = filter_entry.getCStr(FILTER_ATTR_CN_POS); const char* rule = filter_entry.getCStr(FILTER_ATTR_RULE_POS); U_INTERNAL_DUMP("RULE = %S FILTRO = %S", rule, filtro) // get policy attribute from LDAP ULDAP ldap_url; char first_char = rule[0]; bool policy_by_url = (first_char != '('); if (policy_by_url) { if (first_char == '/') { static char url[1024]; (void) snprintf(url, sizeof(url), "ldap://%s%s", LDAP_host.c_str(), rule); rule = url; } if (ldap_url.init(rule) == false || ldap_url.set_protocol() == false || ldap_url.simple_bind() == false) { U_ERROR("login to LDAP with URL failed..."); } n = ldap_url.search(); } else { n = ldap.search("o=Policies,o=tnet", LDAP_SCOPE_SUBTREE, (char**)policy_attr_name, rule); } if (n <= 0) U_ERROR("cannot find policy from LDAP..."); ULDAPEntry policy_entry(POLICY_NUM_ATTR, policy_attr_name, n); if (policy_by_url) ldap_url.get(policy_entry); else ldap.get(policy_entry); // init log const char* log_name = filtro; # include "common2.cpp" // loop for every policy int j, k; char ipmask[64]; const char* ptr; const char* policy; const char* ip_mask; const char* ip_device; char request_buffer[4096 * 4]; const char* binddn_device = LDAP_binddn_device.c_str(); for (i = 0; i < n; ++i) { policy = policy_entry.getCStr(POLICY_ATTR_CN_POS, i); U_INTERNAL_DUMP("POLICY = %S %S", policy_entry[i], policy) // data policy avvio ricerca lista device usando valore attributo policy <tnetLrpIpNetworkNumber> ip_mask = policy_entry.getCStr(POLICY_ATTR_IPMASK_POS, i); (void) snprintf(ipmask, sizeof(ipmask), "(tnetLrpIpHostNumber=%s*)", ip_mask); j = ldap.search(binddn_device, LDAP_SCOPE_SUBTREE, (char**)device_attr_name, ipmask); if (j <= 0) continue; ptr = policy_entry.getCStr(POLICY_ATTR_POLICY_POS, i); // check if to skip xml header... if (U_STRNEQ(ptr, "<?xml")) { ptr += 5; while (*ptr++ != '\n'); } // build request static const char* request_tmpl = \ // "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE REQUEST SYSTEM \"lrp_request.dtd\">" "<REQUEST sid=\"sid1\" version=\"1\"><IMPORT-POLICYLABEL name=\"%s\">%s</IMPORT-POLICYLABEL></REQUEST>" "<REQUEST sid=\"sid2\" version=\"1\"><EXECUTE-POLICYLABEL name=\"%s\" command=\"%s\"/></REQUEST>"; request_size = u__snprintf(request_buffer, sizeof(request_buffer), request_tmpl, policy, ptr, policy, operation); request = UString(request_buffer, request_size); // write request to file # include "common3.cpp" // set devices attribute for LDAP ULDAPEntry device_entry(DEVICE_NUM_ATTR, device_attr_name, j); // get devices attribute from LDAP // loop for every device // fork: child // send request to device // write response to file # include "common4.cpp" // parent } exit_value = proc.waitAll(); log.close(); }
void run(int argc, char* argv[], char* env[]) { U_TRACE(5, "Application::run(%d,%p,%p)", argc, argv, env) UApplication::run(argc, argv, env); U_SYSCALL_VOID_NO_PARAM(xmlInitParser); // init libxml LIBXML_TEST_VERSION // manage options num_args = (argc - optind); U_INTERNAL_DUMP("optind = %d num_args = %d", optind, num_args) if (UApplication::isOptions()) cfg_str = opt['c']; // manage file configuration if (cfg_str.empty()) cfg_str = U_STRING_FROM_CONSTANT("XAdES.ini"); // ---------------------------------------------------------------------------------------------------------------------------------- // XAdES signature - configuration parameters // ---------------------------------------------------------------------------------------------------------------------------------- // DigestAlgorithm md2 | md5 | sha | sha1 | sha224 | sha256 | sha384 | sha512 | mdc2 | ripmed160 // // SigningTime this property contains the time at which the signer claims to have performed the signing process (yes/no) // ClaimedRole this property contains claimed or certified roles assumed by the signer in creating the signature // // this property contains the indication of the purported place where the signer claims to have produced the signature // ------------------------------------------------------------------------------------------------------------------- // ProductionPlaceCity // ProductionPlaceStateOrProvince // ProductionPlacePostalCode // ProductionPlaceCountryName // ------------------------------------------------------------------------------------------------------------------- // // DataObjectFormatMimeType this property identifies the format of a signed data object (when electronic signatures // are not exchanged in a restricted context) to enable the presentation to the verifier or // use by the verifier (text, sound or video) in exactly the same way as intended by the signer // // CAStore // ArchiveTimeStamp the time-stamp token within this property covers the archive validation data // // SignatureTimeStamp the time-stamp token within this property covers the digital signature value element // Schema the pathname XML Schema of XAdES // ---------------------------------------------------------------------------------------------------------------------------------- cfg.UFile::setPath(cfg_str); UString x(U_CAPACITY); UServices::readEOF(STDIN_FILENO, x); if (x.empty()) U_ERROR("cannot read data from <stdin>"); (void) document.reserve(x.size()); UBase64::decode(x, document); if (document.empty()) U_ERROR("decoding data read failed"); // manage arguments... if ( U_DATA_URI && *U_DATA_URI == '\0') { U_ERROR("DATA_URI is mandatory"); } if ( U_X509 && *U_X509 == '\0') { U_ERROR("X509 is mandatory"); } if ( U_KEY_HANDLE && *U_KEY_HANDLE == '\0') { U_ERROR("KEY_HANDLE is mandatory"); } UCertificate cert(UString(U_X509)); if (cert.isValid() == false) U_ERROR("certificate not valid"); U_INTERNAL_DUMP("U_CA_STORE = %S", U_CA_STORE) xades_c = (U_CA_STORE != U_NULLPTR); digest_algorithm = getOptionValue(U_DIGEST_ALGORITHM, "DigestAlgorithm"); alg = u_dgst_get_algoritm(digest_algorithm.c_str()); if (alg == -1) U_ERROR("I can't find the digest algorithm for: %s", digest_algorithm.data()); signing_time = getOptionValue(U_SIGNING_TIME, "SigningTime").strtol(); claimed_role = getOptionValue(U_CLAIMED_ROLE, "ClaimedRole"); production_place_city = getOptionValue(U_PRODUCTION_PLACE_CITY, "ProductionPlaceCity"); production_place_state_or_province = getOptionValue(U_PRODUCTION_PLACE_STATE_OR_PROVINCE, "ProductionPlaceStateOrProvince"); production_place_postal_code = getOptionValue(U_PRODUCTION_PLACE_POSTAL_CODE, "ProductionPlacePostalCode"); production_place_country_name = getOptionValue(U_PRODUCTION_PLACE_COUNTRY_NAME, "ProductionPlaceCountryName"); data_object_format_mimetype = getOptionValue("", "DataObjectFormatMimeType"); if (xades_c == false) num_ca = 0; else { // XAdES-C // ------------------------------------------------------------------------------------------------------------- str_CApath = getOptionValue(U_CA_STORE, "CAStore"); signature_timestamp = getOptionValue(U_SIGNATURE_TIMESTAMP, "SignatureTimeStamp"); if (str_CApath.empty() || UServices::setupOpenSSLStore(U_NULLPTR, str_CApath.c_str()) == false) { U_ERROR("error on setting CA Store: %S", str_CApath.data()); } num_ca = cert.getSignerCertificates(vec_ca, U_NULLPTR, 0); if (UCertificate::verify_result == false) { UServices::setVerifyStatus(); U_ERROR("error on verifying the certificate: %.*s", u_buffer_len, u_buffer); } // ------------------------------------------------------------------------------------------------------------- } u_base64_max_columns = U_OPENSSL_BASE64_MAX_COLUMN; U_line_terminator_len = 2; UString modulus = cert.getModulus(), exponent = cert.getExponent(); X509IssuerName = cert.getIssuerForLDAP(), X509SubjectName = cert.getSubjectForLDAP(), X509Certificate = cert.getEncoded("DER"); X509SerialNumber = cert.getSerialNumber(); UString X509CertificateValue(U_CAPACITY), KeyInfo(U_CAPACITY); UBase64::encode(X509Certificate, X509CertificateValue); u_base64_max_columns = 0; KeyInfo.snprintf(U_CONSTANT_TO_PARAM(U_XMLDSIG_KEYINFO_TEMPLATE), U_STRING_TO_TRACE(modulus), U_STRING_TO_TRACE(exponent), U_STRING_TO_TRACE(X509SubjectName), U_STRING_TO_TRACE(X509IssuerName), X509SerialNumber, U_STRING_TO_TRACE(X509CertificateValue)); UString ObjectDigestValue(200U), Reference(U_CAPACITY), dataObjectFormat(U_CAPACITY), XMLDSIGReference(U_CAPACITY), XMLDSIGReferenceC14N(U_CAPACITY); // --------------------------------------------------------------------------------------------------------------- // check for OOffice or MS-Word document... // --------------------------------------------------------------------------------------------------------------- utility.handlerConfig(cfg); (void) utility.checkDocument(document, U_DATA_URI, true); // --------------------------------------------------------------------------------------------------------------- for (uint32_t i = 0, n = utility.vdocument.size(); i < n; ++i) { uri = utility.vuri[i]; to_digest = utility.vdocument[i]; // --------------------------------------------------------------------------------------------------------------- // 2. Compute the message digest of the text, m = Hash(C). // --------------------------------------------------------------------------------------------------------------- ObjectDigestValue.setEmpty(); UServices::generateDigest(alg, 0, to_digest, ObjectDigestValue, true); // --------------------------------------------------------------------------------------------------------------- Reference.snprintf(U_CONSTANT_TO_PARAM(U_XMLDSIG_REFERENCE_TEMPLATE), uri.c_str(), U_STRING_TO_TRACE(digest_algorithm), U_STRING_TO_TRACE(ObjectDigestValue)); XMLDSIGReference += Reference; XMLDSIGReferenceC14N += UXML2Document::xmlC14N(Reference); if (data_object_format_mimetype.empty() == false) { dataObjectFormat.snprintf(U_CONSTANT_TO_PARAM(U_XADES_DATA_OBJECT_FORMAT_TEMPLATE), uri.c_str(), U_STRING_TO_TRACE(data_object_format_mimetype)); DataObjectFormat += dataObjectFormat; } } setXAdESReference(); // XAdES management // --------------------------------------------------------------------------------------------------------------- // 3. Encapsulate the message digest in an XML <SignedInfo> element, SI, in canonicalized form. // --------------------------------------------------------------------------------------------------------------- UString SignedInfo(U_CONSTANT_SIZE(U_XMLDSIG_SIGNED_INFO_TEMPLATE) + XMLDSIGReference.size() + XAdESReference.size()); SignedInfo.snprintf(U_CONSTANT_TO_PARAM(U_XMLDSIG_SIGNED_INFO_TEMPLATE), U_STRING_TO_TRACE(digest_algorithm), U_STRING_TO_TRACE(XMLDSIGReference), U_STRING_TO_TRACE(XAdESReference)); UString to_sign = UXML2Document::xmlC14N(SignedInfo); // --------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------- // 4. Compute the RSA signatureValue of the canonicalized <SignedInfo> element, SV = RsaSign(Ks, SI). // --------------------------------------------------------------------------------------------------------------- UString SignatureValue(U_CAPACITY), signatureTimeStamp(U_CAPACITY), archiveTimeStamp(U_CAPACITY); u_base64_max_columns = U_OPENSSL_BASE64_MAX_COLUMN; ENGINE* e; # ifdef _MSWINDOWS_ e = UServices::loadEngine("HCSP", ENGINE_METHOD_RSA); x = U_KEY_HANDLE; # else e = U_NULLPTR; x = UFile::contentOf(UString(U_KEY_HANDLE)); if (x.empty() || (u_pkey = UServices::loadKey(x, U_NULLPTR, true, U_NULLPTR, e)) == U_NULLPTR) { U_ERROR("I can't load the private key: %S", U_KEY_HANDLE); } # ifdef HAVE_OPENSSL_98 if (cert.matchPrivateKey(u_pkey) == false) U_ERROR("the private key doesn't matches the public key of the certificate"); # endif x.clear(); # endif UString sign = UServices::getSignatureValue(alg, to_sign, x, UString::getStringNull(), true, e); u_base64_max_columns = 0; SignatureValue.snprintf(U_CONSTANT_TO_PARAM(U_XMLDSIG_SIGNATURE_VALUE_TEMPLATE), U_STRING_TO_TRACE(sign)); if (signature_timestamp.empty() == false) { to_digest = UXML2Document::xmlC14N(SignatureValue); UString token = getTimeStampToken(to_digest, signature_timestamp); signatureTimeStamp.snprintf(U_CONSTANT_TO_PARAM(U_XADES_SIGNATURE_TIMESTAMP_TEMPLATE), U_STRING_TO_TRACE(token)); } // XAdES-C // ------------------------------------------------------------------------------------------------------------- if (xades_c) setXAdESUnsignedSignatureProperties(); // ------------------------------------------------------------------------------------------------------------- (void) XAdESObject.reserve(U_CONSTANT_SIZE(U_XADES_TEMPLATE) + signedProperties.size() + unsignedSignatureProperties.size() + archiveTimeStamp.size() + signatureTimeStamp.size()); XAdESObject.snprintf(U_CONSTANT_TO_PARAM(U_XADES_TEMPLATE), U_STRING_TO_TRACE(signedProperties), U_STRING_TO_TRACE(unsignedSignatureProperties), U_STRING_TO_TRACE(archiveTimeStamp), U_STRING_TO_TRACE(signatureTimeStamp)); // --------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------- // 5. Compose the final XML document including the signatureValue, this time in non-canonicalized form. // --------------------------------------------------------------------------------------------------------------- UString output(U_CONSTANT_SIZE(U_XMLDSIG_TEMPLATE) + 8192U + SignedInfo.size() + SignatureValue.size() + XAdESObject.size()); if (utility.ooffice) { OpenDocumentStart = U_STRING_FROM_CONSTANT("<document-signatures xmlns=\"urn:oasis:names:tc:opendocument:xmlns:digitalsignature:1.0\">"); OpenDocumentEnd = U_STRING_FROM_CONSTANT("</document-signatures>"); } output.snprintf(U_CONSTANT_TO_PARAM(U_XMLDSIG_TEMPLATE), U_STRING_TO_TRACE(OpenDocumentStart), U_STRING_TO_TRACE(SignedInfo), U_STRING_TO_TRACE(SignatureValue), U_STRING_TO_TRACE(KeyInfo), U_STRING_TO_TRACE(XAdESObject), U_STRING_TO_TRACE(OpenDocumentEnd)); // --------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------- // check for OOffice or MS-Word document... // --------------------------------------------------------------------------------------------------------------- utility.outputDocument(output); // --------------------------------------------------------------------------------------------------------------- }
ULog::ULog(const UString& path, uint32_t _size, const char* dir_log_gz) : UFile(path) { U_TRACE_REGISTER_OBJECT(0, ULog, "%.*S,%u,%S", U_STRING_TO_TRACE(path), _size, dir_log_gz) log_gzip_sz = 0; U_Log_start_stop_msg(this) = false; if (UFile::getPath().equal(U_CONSTANT_TO_PARAM("syslog"))) { lock = 0; ptr_log_data = 0; # ifdef USE_LIBZ buf_path_compress = 0; # endif U_Log_syslog(this) = true; # ifndef __MINGW32__ U_SYSCALL_VOID(openlog, "%S,%d,%d", u_progname, LOG_PID, LOG_LOCAL0); # endif return; } if (UFile::creat(O_RDWR | O_APPEND, 0664) == false) { U_ERROR("cannot creat log file %.*S", U_FILE_TO_TRACE(*this)); return; } ptr_log_data = U_MALLOC_TYPE(log_data); ptr_log_data->file_ptr = 0; if (_size) { uint32_t file_size = UFile::size(); bool bsize = (file_size != _size); U_INTERNAL_DUMP("bsize = %b", bsize) if ((bsize && UFile::ftruncate(_size) == false) || UFile::memmap(PROT_READ | PROT_WRITE) == false) { U_ERROR("cannot init log file %.*S", U_FILE_TO_TRACE(*this)); return; } if (bsize) ptr_log_data->file_ptr = file_size; // append mode else { // NB: we can have a previous crash without resizing the file or we are an other process (apache like log)... char* ptr = (char*) u_find(UFile::map, file_size, U_CONSTANT_TO_PARAM(U_MARK_END)); U_INTERNAL_DUMP("ptr = %p", ptr) if (ptr) { ptr_log_data->file_ptr = ptr - UFile::map; // NB: we can be an other process that manage this file (apache like log)... (void) memcpy(ptr, U_CONSTANT_TO_PARAM(U_MARK_END)); UFile::msync(ptr + U_CONSTANT_SIZE(U_MARK_END), UFile::map, MS_SYNC); } U_INTERNAL_ASSERT_MINOR(ptr_log_data->file_ptr, UFile::st_size) } log_file_sz = UFile::st_size; } U_INTERNAL_DUMP("ptr_log_data->file_ptr = %u UFile::st_size = %u log_gzip_sz = %u", ptr_log_data->file_ptr, UFile::st_size, log_gzip_sz) U_INTERNAL_ASSERT(ptr_log_data->file_ptr <= UFile::st_size) lock = U_NEW(ULock); U_Log_syslog(this) = false; ptr_log_data->gzip_len = 0; ptr_log_data->file_page = ptr_log_data->file_ptr; #ifdef USE_LIBZ char suffix[32]; uint32_t len_suffix = u__snprintf(suffix, sizeof(suffix), ".%4D.gz"); buf_path_compress = U_NEW(UString(MAX_FILENAME_LEN)); char* ptr = buf_path_compress->data(); if (dir_log_gz == 0) { (void) UFile::setPathFromFile(*this, ptr, suffix, len_suffix); buf_path_compress->size_adjust(); index_path_compress = (buf_path_compress->size() - len_suffix + 1); } else { UString name = UFile::getName(); uint32_t len = u__strlen(dir_log_gz, __PRETTY_FUNCTION__), sz = name.size(); U_MEMCPY(ptr, dir_log_gz, len); ptr += len; *ptr++ = '/'; buf_path_compress->size_adjust(len + 1 + sz + len_suffix); U_MEMCPY(ptr, name.data(), sz); ptr += sz; U_MEMCPY(ptr, suffix, len_suffix); index_path_compress = buf_path_compress->distance(ptr) + 1; buf_path_compress->UString::setNullTerminated(); } U_INTERNAL_DUMP("buf_path_compress(%u) = %.*S index_path_compress = %u", buf_path_compress->size(), U_STRING_TO_TRACE(*buf_path_compress), index_path_compress) #endif }
void UThread::close() { U_TRACE_NO_PARAM(0, "UThread::close()") #ifdef _MSWINDOWS_ DWORD _tid = tid; #else pthread_t _tid = tid; #endif tid = 0; U_INTERNAL_DUMP("tid = %p first = %p next = %p", _tid, first, next) U_INTERNAL_ASSERT_POINTER(first) UThread* obj; UThread** ptr = &first; while ((obj = *ptr)) { U_INTERNAL_ASSERT_POINTER(obj) # ifdef _MSWINDOWS_ if (tid == obj->tid) # else if (pthread_equal(tid, obj->tid)) # endif { U_INTERNAL_ASSERT_EQUALS(this, obj) U_INTERNAL_ASSERT_EQUALS(next, obj->next) *ptr = next; next = 0; break; } ptr = &(*ptr)->next; } if (_tid) { # ifdef _MSWINDOWS_ // wait for real w32 thread to cleanup switch (cancel) { case cancelImmediate: TerminateThread((HANDLE)_tid, 0); break; default: SetEvent(cancellation); } (void) WaitForSingleObject((HANDLE)_tid, INFINITE); (void) U_SYSCALL(CloseHandle, "%p", cancellation); (void) U_SYSCALL(CloseHandle, "%p", (HANDLE)_tid); _endthreadex(0); # else # ifdef HAVE_PTHREAD_CANCEL (void) U_SYSCALL(pthread_cancel, "%p", _tid); # endif if (detachstate == PTHREAD_CREATE_JOINABLE) (void) U_SYSCALL(pthread_join, "%p,%p", _tid, 0); # ifdef HAVE_PTHREAD_YIELD else { (void) U_SYSCALL_NO_PARAM(pthread_yield); } # endif # endif } }
U_NO_EXPORT void UProcess::setStdInOutErr(bool fd_stdin, bool fd_stdout, bool fd_stderr) { U_TRACE(1, "UProcess::setStdInOutErr(%b,%b,%b)", fd_stdin, fd_stdout, fd_stderr) #ifdef __MINGW32__ HANDLE hProcess = GetCurrentProcess(); #endif // check if we write to STDIN if (fd_stdin) { # ifdef __MINGW32__ if (hFile[1]) // Created parent-output pipe... { hChildIn = hFile[0]; // Duplicating as inheritable child-input pipe // ------------------------------------------- // (void) U_SYSCALL(DuplicateHandle, "%p,%p,%p,%p,%lu,%b,%lu", hProcess, hFile[0], hProcess, &hChildIn, 0, TRUE, DUPLICATE_SAME_ACCESS); // (void) U_SYSCALL( CloseHandle, "%p", hFile[0]); } else { hChildIn = (HANDLE)_get_osfhandle(filedes[0]); } # else U_INTERNAL_ASSERT_MAJOR(filedes[0],STDERR_FILENO) (void) U_SYSCALL(dup2, "%d,%d", filedes[0], STDIN_FILENO); U_INTERNAL_ASSERT_EQUALS(::fcntl(STDIN_FILENO,F_GETFD,FD_CLOEXEC), 0) # endif } // check if we read from STDOUT if (fd_stdout) { # ifdef __MINGW32__ if (hFile[2]) // Created parent-input pipe... { hChildOut = hFile[3]; // Duplicating as inheritable child-output pipe // ------------------------------------------- // (void) U_SYSCALL(DuplicateHandle, "%p,%p,%p,%p,%lu,%b,%lu", hProcess, hFile[3], hProcess, &hChildOut, 0, TRUE, DUPLICATE_SAME_ACCESS); // (void) U_SYSCALL( CloseHandle, "%p", hFile[3]); } else { hChildOut = (HANDLE)_get_osfhandle(filedes[3]); } # else U_INTERNAL_ASSERT_MAJOR(filedes[3],STDOUT_FILENO) (void) U_SYSCALL(dup2, "%d,%d", filedes[3], STDOUT_FILENO); U_INTERNAL_ASSERT_EQUALS(::fcntl(STDOUT_FILENO,F_GETFD,FD_CLOEXEC), 0) # endif } // check if we read from STDERR if (fd_stderr) { # ifdef __MINGW32__ if (hFile[4]) // Created parent-input pipe... { hChildErr = hFile[5]; // Duplicating as inheritable child-output pipe // ------------------------------------------- // (void) U_SYSCALL(DuplicateHandle, "%p,%p,%p,%p,%lu,%b,%lu", hProcess, hFile[5], hProcess, &hChildErr, 0, TRUE, DUPLICATE_SAME_ACCESS); // (void) U_SYSCALL( CloseHandle, "%p", hFile[5]); } else { hChildErr = (HANDLE)_get_osfhandle(filedes[5]); } # else U_INTERNAL_ASSERT(filedes[5] >= STDOUT_FILENO) (void) U_SYSCALL(dup2, "%d,%d", filedes[5], STDERR_FILENO); U_INTERNAL_ASSERT_EQUALS(::fcntl(STDERR_FILENO,F_GETFD,FD_CLOEXEC), 0) # endif } #ifdef __MINGW32__ CloseHandle(hProcess); #else if (fd_stdin) { U_INTERNAL_DUMP("filedes[0,1] = { %d, %d }", filedes[0], filedes[1]) (void) U_SYSCALL(close, "%d", filedes[0]); if (filedes[1] > STDERR_FILENO) (void) U_SYSCALL(close, "%d", filedes[1]); } if (fd_stdout) { U_INTERNAL_DUMP("filedes[2,3] = { %d, %d }", filedes[2], filedes[3]) (void) U_SYSCALL(close, "%d", filedes[3]); if (filedes[2] > STDERR_FILENO) (void) U_SYSCALL(close, "%d", filedes[2]); } if (fd_stderr) { U_INTERNAL_DUMP("filedes[4,5] = { %d, %d }", filedes[4], filedes[5]) (void) U_SYSCALL(close, "%d", filedes[5]); if (filedes[4] > STDERR_FILENO) (void) U_SYSCALL(close, "%d", filedes[4]); } #endif }
void run(int argc, char* argv[], char* env[]) { U_TRACE(5, "Application::run(%d,%p,%p)", argc, argv, env) UApplication::run(argc, argv, env); // manage options if (UApplication::isOptions()) cfg_str = opt['c']; // manage arg operation // manage file configuration if (cfg_str.empty()) cfg_str = U_STRING_FROM_CONSTANT("form_completion.cfg"); (void) cfg.open(cfg_str); int LDAP_port; UString var_env_name, scan_form, LDAP_host, LDAP_searchbase, password, username, form_template, LDAP_rootdn, LDAP_rootpw, subject_attr; // -------------------------------------------------------------------------------------------------------------- // configuration parameters // -------------------------------------------------------------------------------------------------------------- // X509_SUBJECT_VARIABLE var environment to elaborate (ex: X509_SUBJECT) // X509_SUBJECT_FILTER scanf form to extract data (ex: /C=IT/L=Rome/O=Eraclito/OU=Tac/CN=%[^/]s/Email=%*s) // LDAP_SERVER_ADDRESS name ldap host (ex: slessi) // LDAP_SERVER_PORT port ldap host (ex: 389) // LDAP_SERVER_BASE // LDAP_SERVER_ROOTDN bind DN for ldap query data // LDAP_SERVER_ROOTPW bind password for ldap query data // LDAP_SUBJECT_ATTRIBUTE attribute for query filter // LDAP_USER_ATTRIBUTE name user attribute (ex: uid) // LDAP_PASSWD_ATTRIBUTE name password attribute (ex: tacPassword) // TEMPLATE name form completion to print (ex: ./lms1.templ) // -------------------------------------------------------------------------------------------------------------- var_env_name = cfg[U_STRING_FROM_CONSTANT("X509_SUBJECT_VARIABLE")]; scan_form = cfg[U_STRING_FROM_CONSTANT("X509_SUBJECT_FILTER")]; LDAP_host = cfg[U_STRING_FROM_CONSTANT("LDAP_SERVER_ADDRESS")]; LDAP_searchbase = cfg[U_STRING_FROM_CONSTANT("LDAP_SERVER_BASE")]; LDAP_rootdn = cfg[U_STRING_FROM_CONSTANT("LDAP_SERVER_ROOTDN")]; LDAP_rootpw = cfg[U_STRING_FROM_CONSTANT("LDAP_SERVER_ROOTPW")]; subject_attr = cfg[U_STRING_FROM_CONSTANT("LDAP_SUBJECT_ATTRIBUTE")]; password = cfg[U_STRING_FROM_CONSTANT("LDAP_PASSWD_ATTRIBUTE")]; username = cfg[U_STRING_FROM_CONSTANT("LDAP_USER_ATTRIBUTE")]; form_template = cfg[U_STRING_FROM_CONSTANT("TEMPLATE")]; LDAP_port = cfg.readLong(U_STRING_FROM_CONSTANT("LDAP_SERVER_PORT"), 389); // scanf char buf[256]; const char* value = (const char*) U_SYSCALL(getenv, "%S", var_env_name.c_str()); int n = U_SYSCALL(sscanf, "%S,%S,%p,%p,%p,%p", value, scan_form.c_str(), &buf[0]); if (n != 1) U_ERROR("scanf error on var env <%s>...", var_env_name.c_str()); U_INTERNAL_DUMP("sscanf() result = \"%s\"", buf) // login to LDAP ULDAP ldap; if (ldap.init(LDAP_host.c_str(), (LDAP_port ? LDAP_port : LDAP_PORT)) == false || ldap.set_protocol() == false || ldap.bind(LDAP_rootdn.c_str(), LDAP_rootpw.c_str()) == false) { U_ERROR("login to LDAP failed..."); } // search to LDAP char buffer[4096]; const char* attr_name[] = { username.c_str(), password.c_str(), 0 }; (void) snprintf(buffer, sizeof(buffer), "%s=%s,%.*s", subject_attr.c_str(), buf, U_STRING_TO_TRACE(LDAP_searchbase)); n = ldap.search(buffer, LDAP_SCOPE_BASE, (char**)attr_name); if (n != 1) U_ERROR("search error on ldap..."); ULDAPEntry entry(2, attr_name, 1); ldap.get(entry); const char* sname = entry.getCStr(0); const char* spassword = entry.getCStr(1); // write to stdout (void) U_SYSCALL(printf, "%S,%S,%S", UFile::contentOf(form_template).data(), sname, spassword); }