PKIError GenerateCertificate (const UTF8String_t *subjectName, const UTF8String_t *issuerName, const UTCTime_t *notBefore, const UTCTime_t *notAfter, const BIT_STRING_t *subjectPublicKey, const BIT_STRING_t *issuerPrivateKey, ByteArray *encodedCertificate) { FUNCTION_INIT(); asn_enc_rval_t ec; /* Encoder return value */ Certificate_t *certificate = NULL; /* Type to encode */ AttributeTypeAndValue_t *issuerTypeAndValue = NULL; AttributeTypeAndValue_t *subjectTypeAndValue = NULL; RelativeDistinguishedName_t *issuerRDN = NULL; RelativeDistinguishedName_t *subjectRDN = NULL; uint8_t *uint8Pointer = NULL; ByteArray tbs = BYTE_ARRAY_INITIALIZER; uint8_t signature[SIGN_FULL_SIZE]; uint8_t sha256[SHA_256_HASH_LEN]; uint8_t tbsDer[ISSUER_MAX_CERT_SIZE]; long serialNumber = 0; CHECK_NULL(subjectName, ISSUER_X509_NULL_PASSED); CHECK_NULL(issuerName, ISSUER_X509_NULL_PASSED); CHECK_NULL(notBefore, ISSUER_X509_NULL_PASSED); CHECK_NULL(notAfter, ISSUER_X509_NULL_PASSED); CHECK_NULL(subjectPublicKey, ISSUER_X509_NULL_PASSED); CHECK_NULL(issuerPrivateKey, ISSUER_X509_NULL_PASSED); CHECK_NULL_BYTE_ARRAY_PTR(encodedCertificate, ISSUER_X509_NULL_PASSED); CHECK_LESS_EQUAL(ISSUER_MAX_CERT_SIZE, encodedCertificate->len, ISSUER_X509_WRONG_BYTE_ARRAY_LEN); /* Allocate the memory */ certificate = OICCalloc(1, sizeof(Certificate_t)); // not malloc! CHECK_NULL(certificate, ISSUER_X509_MEMORY_ALLOC_FAILED); issuerTypeAndValue = OICCalloc(1, sizeof(AttributeTypeAndValue_t)); CHECK_NULL(issuerTypeAndValue, ISSUER_X509_MEMORY_ALLOC_FAILED); issuerRDN = OICCalloc(1, sizeof(RelativeDistinguishedName_t)); CHECK_NULL(issuerRDN, ISSUER_X509_MEMORY_ALLOC_FAILED); subjectTypeAndValue = OICCalloc(1, sizeof(AttributeTypeAndValue_t)); CHECK_NULL(subjectTypeAndValue, ISSUER_X509_MEMORY_ALLOC_FAILED); subjectRDN = OICCalloc(1, sizeof(RelativeDistinguishedName_t)); CHECK_NULL(subjectRDN, ISSUER_X509_MEMORY_ALLOC_FAILED); //set issuer name issuerTypeAndValue->value = *issuerName; issuerTypeAndValue->type.buf = (uint8_t *)g_COMMON_NAME_OID; //2.5.4.3 issuerTypeAndValue->type.size = sizeof(g_COMMON_NAME_OID) / sizeof(g_COMMON_NAME_OID[0]); ASN_SET_ADD(issuerRDN, issuerTypeAndValue); ASN_SEQUENCE_ADD(&(certificate->tbsCertificate.issuer), issuerRDN); //set subject name subjectTypeAndValue->value = *subjectName; subjectTypeAndValue->type.buf = (uint8_t *)g_COMMON_NAME_OID; //2.5.4.3 subjectTypeAndValue->type.size = sizeof(g_COMMON_NAME_OID) / sizeof(g_COMMON_NAME_OID[0]); ASN_SET_ADD(subjectRDN, subjectTypeAndValue); ASN_SEQUENCE_ADD(&(certificate->tbsCertificate.subject), subjectRDN); //set validity certificate->tbsCertificate.validity.notBefore = *notBefore; certificate->tbsCertificate.validity.notAfter = *notAfter; //set X.509 certificate version certificate->tbsCertificate.version = X509_V2; //set serial number certificate->tbsCertificate.serialNumber = 0; CHECK_CALL(InitCKMInfo); CHECK_CALL(GetNextSerialNumber, &serialNumber); certificate->tbsCertificate.serialNumber = serialNumber; serialNumber++; CHECK_CALL(SetNextSerialNumber, serialNumber); CHECK_CALL(SaveCKMInfo); //set signature algorithm in TBS certificate->tbsCertificate.signature.algorithm.buf = (uint8_t *)g_ECDSA_WITH_SHA256_OID; //1.2.840.10045.4.3.2 certificate->tbsCertificate.signature.algorithm.size = sizeof(g_ECDSA_WITH_SHA256_OID) / sizeof(g_ECDSA_WITH_SHA256_OID[0]); certificate->tbsCertificate.signature.nul = OICCalloc(1, sizeof(NULL_t)); CHECK_NULL(certificate->tbsCertificate.signature.nul, ISSUER_X509_MEMORY_ALLOC_FAILED); //set subject Public Key algorithm certificate->tbsCertificate.subjectPublicKeyInfo.algorithm.algorithm.buf = (uint8_t *)g_EC_PUBLIC_KEY_OID; //1.2.840.10045.2.1 certificate->tbsCertificate.subjectPublicKeyInfo.algorithm.algorithm.size = sizeof(g_EC_PUBLIC_KEY_OID) / sizeof(g_EC_PUBLIC_KEY_OID[0]); //set subject Public Key curve certificate->tbsCertificate.subjectPublicKeyInfo.algorithm.id_ecPublicKey = OICCalloc(1, sizeof(OBJECT_IDENTIFIER_t)); CHECK_NULL(certificate->tbsCertificate.subjectPublicKeyInfo.algorithm.id_ecPublicKey, ISSUER_X509_MEMORY_ALLOC_FAILED); certificate->tbsCertificate.subjectPublicKeyInfo.algorithm.id_ecPublicKey->buf = (uint8_t *)g_PRIME_256_V1_OID; //1.2.840.10045.3.1.7 certificate->tbsCertificate.subjectPublicKeyInfo.algorithm.id_ecPublicKey->size = sizeof(g_PRIME_256_V1_OID) / sizeof(g_PRIME_256_V1_OID[0]); //set subject Public Key certificate->tbsCertificate.subjectPublicKeyInfo.subjectPublicKey = *subjectPublicKey; //set signature algorithm certificate->signatureAlgorithm.algorithm.buf = (uint8_t *)g_ECDSA_WITH_SHA256_OID; certificate->signatureAlgorithm.algorithm.size = sizeof(g_ECDSA_WITH_SHA256_OID) / sizeof(g_ECDSA_WITH_SHA256_OID[0]); certificate->signatureAlgorithm.nul = OICCalloc(1, sizeof(NULL_t)); CHECK_NULL(certificate->signatureAlgorithm.nul, ISSUER_X509_MEMORY_ALLOC_FAILED); //encode TBS to DER ec = der_encode_to_buffer(&asn_DEF_TBSCertificate, &(certificate->tbsCertificate), tbsDer, ISSUER_MAX_CERT_SIZE); CHECK_COND(ec.encoded > 0, ISSUER_X509_DER_ENCODE_FAIL); tbs.len = ec.encoded; tbs.data = tbsDer; GET_SHA_256(tbs, sha256); CHECK_COND(uECC_sign((issuerPrivateKey->buf) + 1, sha256, signature), ISSUER_X509_SIGNATURE_FAIL); //additional byte for ASN1_UNCOMPRESSED_KEY_ID // ECDSA-Sig-Value ::= SEQUENCE { r INTEGER, s INTEGER } (RFC 5480) certificate->signatureValue.size = SIGN_FULL_SIZE + 6;// size for SEQUENCE ID + 2 * INTEGER ID // if first byte of positive INTEGER exceed 127 add 0 byte before if (signature[0] > 127) { certificate->signatureValue.size ++; } // if first byte of positive INTEGER exceed 127 add 0 byte before if (signature[SIGN_R_LEN] > 127) { certificate->signatureValue.size ++; } certificate->signatureValue.buf = OICCalloc(certificate->signatureValue.size, sizeof(uint8_t)); CHECK_NULL(certificate->signatureValue.buf, ISSUER_X509_MEMORY_ALLOC_FAILED); *(certificate->signatureValue.buf) = (12 << 2); //ASN.1 SEQUENCE ID *(certificate->signatureValue.buf + 1) = certificate->signatureValue.size - 2; //ASN.1 SEQUENCE size uint8Pointer = certificate->signatureValue.buf + 2; //skip SEQUENCE ID and size *uint8Pointer = (2 << 0); //ASN.1 INTEGER ID // if first byte of positive INTEGER exceed 127 add 0 byte before if (signature[0] > 127) { *(uint8Pointer + 1) = SIGN_R_LEN + 1; //ASN.1 INTEGER size uint8Pointer += 3; //skip INTEGER ID and size } else { *(uint8Pointer + 1) = SIGN_R_LEN; //ASN.1 INTEGER SIZE uint8Pointer += 2; //skip INTEGER ID and size } memcpy(uint8Pointer, signature, SIGN_R_LEN); uint8Pointer += SIGN_R_LEN; //skip first part of signature *uint8Pointer = (2 << 0); //ASN.1 INTEGER ID // if first byte of positive INTEGER exceed 127 add 0 byte before if (signature [SIGN_R_LEN] > 127) { *(uint8Pointer + 1) = SIGN_S_LEN + 1; //ASN.1 INTEGER size uint8Pointer += 3; //skip INTEGER ID and size } else { *(uint8Pointer + 1) = SIGN_S_LEN; //ASN.1 INTEGER size uint8Pointer += 2; //skip INTEGER ID and size } memcpy(uint8Pointer, signature + SIGN_R_LEN, SIGN_S_LEN); ec = der_encode_to_buffer(&asn_DEF_Certificate, certificate, encodedCertificate->data, ISSUER_MAX_CERT_SIZE); CHECK_COND(ec.encoded > 0, ISSUER_X509_DER_ENCODE_FAIL); encodedCertificate->len = ec.encoded; FUNCTION_CLEAR( if (issuerTypeAndValue) { issuerTypeAndValue->value.buf = NULL; issuerTypeAndValue->type.buf = NULL; } if (subjectTypeAndValue) { subjectTypeAndValue->value.buf = NULL; subjectTypeAndValue->type.buf = NULL; } if (certificate) { certificate->tbsCertificate.validity.notBefore.buf = NULL; certificate->tbsCertificate.validity.notAfter.buf = NULL; certificate->tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.buf = NULL; certificate->tbsCertificate.signature.algorithm.buf = NULL; certificate->tbsCertificate.subjectPublicKeyInfo.algorithm.algorithm.buf = NULL; certificate->tbsCertificate.subjectPublicKeyInfo.algorithm.id_ecPublicKey->buf = NULL; certificate->signatureAlgorithm.algorithm.buf = NULL; } ASN_STRUCT_FREE(asn_DEF_Certificate, certificate); certificate = NULL; );
/** * Transaction 2 - T2 * * Read from Subscriber: * * Input: * SubscriberNumber * * Output: * Location * Changed by * Changed Timestamp * Name */ int T2(void * obj, const SubscriberNumber number, Location * readLocation, ChangedBy changed_by, ChangedTime changed_time, SubscriberName subscriberName, BenchmarkTime * transaction_time){ Ndb * pNDB = (Ndb *) obj; BenchmarkTime start; get_time(&start); int check; NdbRecAttr * check2; NdbConnection * MyTransaction = pNDB->startTransaction(); if (MyTransaction == NULL) error_handler("T2: startTranscation", pNDB->getNdbErrorString(), 0); NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE); CHECK_NULL(MyOperation, "T2: getNdbOperation", MyTransaction); check = MyOperation->readTuple(); CHECK_MINUS_ONE(check, "T2: readTuple", MyTransaction); check = MyOperation->equal(IND_SUBSCRIBER_NUMBER, number); CHECK_MINUS_ONE(check, "T2: equal subscriber", MyTransaction); check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION, (char *)readLocation); CHECK_NULL(check2, "T2: getValue location", MyTransaction); check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY, changed_by); CHECK_NULL(check2, "T2: getValue changed_by", MyTransaction); check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME, changed_time); CHECK_NULL(check2, "T2: getValue changed_time", MyTransaction); check2 = MyOperation->getValue(IND_SUBSCRIBER_NAME, subscriberName); CHECK_NULL(check2, "T2: getValue name", MyTransaction); check = MyTransaction->execute( Commit ); CHECK_MINUS_ONE(check, "T2: Commit", MyTransaction); pNDB->closeTransaction(MyTransaction); get_time(transaction_time); time_diff(transaction_time, &start); return 0; }
/** * Transaction 5 - T5 * * Delete session * * Input: * SubscriberNumber * ServerId * ServerBit * DoRollback * Output: * ChangedBy * ChangedTime * Location * BranchExecuted */ void userTransaction_T5(UserHandle * uh, SubscriberNumber inNumber, ServerId inServerId, ServerBit inServerBit, DoRollback inDoRollback, BranchExecuted * outBranchExecuted){ Ndb * pNDB = uh->pNDB; DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId); NdbConnection * MyTransaction = 0; NdbOperation * MyOperation = 0; char outChangedBy [sizeof(ChangedBy) +(4-(sizeof(ChangedBy) & 3))]; char outChangedTime [sizeof(ChangedTime)+(4-(sizeof(ChangedTime) & 3))]; Location outLocation; GroupId groupId; ActiveSessions sessions; Permission permission; SubscriberSuffix inSuffix; int check; NdbRecAttr * check2; MyTransaction = pNDB->startTransaction(); if (MyTransaction == NULL) error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError()); MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE); CHECK_NULL(MyOperation, "T5-1: getNdbOperation", MyTransaction); MyOperation->interpretedUpdateTuple(); MyOperation->equal(IND_SUBSCRIBER_NUMBER, inNumber); MyOperation->getValue(IND_SUBSCRIBER_LOCATION, (char *)&outLocation); MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY, &outChangedBy[0]); MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME, &outChangedTime[0]); MyOperation->getValue(IND_SUBSCRIBER_GROUP, (char *)&groupId); MyOperation->getValue(IND_SUBSCRIBER_SESSIONS, (char *)&sessions); MyOperation->subValue(IND_SUBSCRIBER_SESSIONS, (uint32)inServerBit); MyTransaction->execute( NoCommit ); /* Operation 2 */ MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE); CHECK_NULL(MyOperation, "T5-2: getNdbOperation", MyTransaction); MyOperation->readTuple(); MyOperation->equal(IND_GROUP_ID, (char*)&groupId); MyOperation->getValue(IND_GROUP_ALLOW_DELETE, (char *)&permission); check = MyTransaction->execute( NoCommit ); CHECK_MINUS_ONE(check, "T5-2: NoCommit", MyTransaction); if(((permission & inServerBit) == inServerBit) && ((sessions & inServerBit) == inServerBit)){ memcpy(inSuffix, &inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH); DEBUG2("deleting(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix); /* Operation 3 */ MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE); CHECK_NULL(MyOperation, "T5-3: getNdbOperation", MyTransaction); MyOperation->deleteTuple(); MyOperation->equal(IND_SESSION_SUBSCRIBER, (char*)inNumber); MyOperation->equal(IND_SESSION_SERVER, (char*)&inServerId); /* Operation 4 */ /* Operation 5 */ MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE); CHECK_NULL(MyOperation, "T5-5: getNdbOperation", MyTransaction); MyOperation->interpretedUpdateTuple(); MyOperation->equal(IND_SERVER_ID, (char*)&inServerId); MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX, (char*)inSuffix); MyOperation->incValue(IND_SERVER_DELETES, (uint32)1); (* outBranchExecuted) = 1; } else { (* outBranchExecuted) = 0; DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - ")); DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - ")); } if(!inDoRollback && (* outBranchExecuted)){ DEBUG("commit\n"); check = MyTransaction->execute( Commit ); CHECK_MINUS_ONE(check, "T5: Commit", MyTransaction); } else { DEBUG("rollback\n"); check = MyTransaction->execute(Rollback); CHECK_MINUS_ONE(check, "T5:Rollback", MyTransaction); } pNDB->closeTransaction(MyTransaction); }
JNIEXPORT void JNICALL Java_sun_font_FontConfigManager_getFontConfig (JNIEnv *env, jclass obj, jstring localeStr, jobject fcInfoObj, jobjectArray fcCompFontArray, jboolean includeFallbacks) { FcNameParseFuncType FcNameParse; FcPatternAddStringFuncType FcPatternAddString; FcConfigSubstituteFuncType FcConfigSubstitute; FcDefaultSubstituteFuncType FcDefaultSubstitute; FcFontMatchFuncType FcFontMatch; FcPatternGetStringFuncType FcPatternGetString; FcPatternDestroyFuncType FcPatternDestroy; FcPatternGetCharSetFuncType FcPatternGetCharSet; FcFontSortFuncType FcFontSort; FcFontSetDestroyFuncType FcFontSetDestroy; FcCharSetUnionFuncType FcCharSetUnion; FcCharSetSubtractCountFuncType FcCharSetSubtractCount; FcGetVersionFuncType FcGetVersion; FcConfigGetCacheDirsFuncType FcConfigGetCacheDirs; FcStrListNextFuncType FcStrListNext; FcStrListDoneFuncType FcStrListDone; int i, arrlen; jobject fcCompFontObj; jstring fcNameStr, jstr; const char *locale, *fcName; FcPattern *pattern; FcResult result; void* libfontconfig; jfieldID fcNameID, fcFirstFontID, fcAllFontsID, fcVersionID, fcCacheDirsID; jfieldID familyNameID, styleNameID, fullNameID, fontFileID; jmethodID fcFontCons; char* debugMinGlyphsStr = getenv("J2D_DEBUG_MIN_GLYPHS"); CHECK_NULL(fcInfoObj); CHECK_NULL(fcCompFontArray); jclass fcInfoClass = (*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigInfo"); CHECK_NULL(fcInfoClass); jclass fcCompFontClass = (*env)->FindClass(env, "sun/font/FontConfigManager$FcCompFont"); CHECK_NULL(fcCompFontClass); jclass fcFontClass = (*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigFont"); CHECK_NULL(fcFontClass); CHECK_NULL(fcVersionID = (*env)->GetFieldID(env, fcInfoClass, "fcVersion", "I")); CHECK_NULL(fcCacheDirsID = (*env)->GetFieldID(env, fcInfoClass, "cacheDirs", "[Ljava/lang/String;")); CHECK_NULL(fcNameID = (*env)->GetFieldID(env, fcCompFontClass, "fcName", "Ljava/lang/String;")); CHECK_NULL(fcFirstFontID = (*env)->GetFieldID(env, fcCompFontClass, "firstFont", "Lsun/font/FontConfigManager$FontConfigFont;")); CHECK_NULL(fcAllFontsID = (*env)->GetFieldID(env, fcCompFontClass, "allFonts", "[Lsun/font/FontConfigManager$FontConfigFont;")); CHECK_NULL(fcFontCons = (*env)->GetMethodID(env, fcFontClass, "<init>", "()V")); CHECK_NULL(familyNameID = (*env)->GetFieldID(env, fcFontClass, "familyName", "Ljava/lang/String;")); CHECK_NULL(styleNameID = (*env)->GetFieldID(env, fcFontClass, "styleStr", "Ljava/lang/String;")); CHECK_NULL(fullNameID = (*env)->GetFieldID(env, fcFontClass, "fullName", "Ljava/lang/String;")); CHECK_NULL(fontFileID = (*env)->GetFieldID(env, fcFontClass, "fontFile", "Ljava/lang/String;")); if ((libfontconfig = openFontConfig()) == NULL) { return; } FcNameParse = (FcNameParseFuncType)dlsym(libfontconfig, "FcNameParse"); FcPatternAddString = (FcPatternAddStringFuncType)dlsym(libfontconfig, "FcPatternAddString"); FcConfigSubstitute = (FcConfigSubstituteFuncType)dlsym(libfontconfig, "FcConfigSubstitute"); FcDefaultSubstitute = (FcDefaultSubstituteFuncType) dlsym(libfontconfig, "FcDefaultSubstitute"); FcFontMatch = (FcFontMatchFuncType)dlsym(libfontconfig, "FcFontMatch"); FcPatternGetString = (FcPatternGetStringFuncType)dlsym(libfontconfig, "FcPatternGetString"); FcPatternDestroy = (FcPatternDestroyFuncType)dlsym(libfontconfig, "FcPatternDestroy"); FcPatternGetCharSet = (FcPatternGetCharSetFuncType)dlsym(libfontconfig, "FcPatternGetCharSet"); FcFontSort = (FcFontSortFuncType)dlsym(libfontconfig, "FcFontSort"); FcFontSetDestroy = (FcFontSetDestroyFuncType)dlsym(libfontconfig, "FcFontSetDestroy"); FcCharSetUnion = (FcCharSetUnionFuncType)dlsym(libfontconfig, "FcCharSetUnion"); FcCharSetSubtractCount = (FcCharSetSubtractCountFuncType)dlsym(libfontconfig, "FcCharSetSubtractCount"); FcGetVersion = (FcGetVersionFuncType)dlsym(libfontconfig, "FcGetVersion"); if (FcNameParse == NULL || FcPatternAddString == NULL || FcConfigSubstitute == NULL || FcDefaultSubstitute == NULL || FcFontMatch == NULL || FcPatternGetString == NULL || FcPatternDestroy == NULL || FcPatternGetCharSet == NULL || FcFontSetDestroy == NULL || FcCharSetUnion == NULL || FcGetVersion == NULL || FcCharSetSubtractCount == NULL) {/* problem with the library: return.*/ closeFontConfig(libfontconfig, JNI_FALSE); return; } (*env)->SetIntField(env, fcInfoObj, fcVersionID, (*FcGetVersion)()); /* Optionally get the cache dir locations. This isn't * available until v 2.4.x, but this is OK since on those later versions * we can check the time stamps on the cache dirs to see if we * are out of date. There are a couple of assumptions here. First * that the time stamp on the directory changes when the contents are * updated. Secondly that the locations don't change. The latter is * most likely if a new version of fontconfig is installed, but we also * invalidate the cache if we detect that. Arguably even that is "rare", * and most likely is tied to an OS upgrade which gets a new file anyway. */ FcConfigGetCacheDirs = (FcConfigGetCacheDirsFuncType)dlsym(libfontconfig, "FcConfigGetCacheDirs"); FcStrListNext = (FcStrListNextFuncType)dlsym(libfontconfig, "FcStrListNext"); FcStrListDone = (FcStrListDoneFuncType)dlsym(libfontconfig, "FcStrListDone"); if (FcStrListNext != NULL && FcStrListDone != NULL && FcConfigGetCacheDirs != NULL) { FcStrList* cacheDirs; FcChar8* cacheDir; int cnt = 0; jobject cacheDirArray = (*env)->GetObjectField(env, fcInfoObj, fcCacheDirsID); int max = (*env)->GetArrayLength(env, cacheDirArray); cacheDirs = (*FcConfigGetCacheDirs)(NULL); if (cacheDirs != NULL) { while ((cnt < max) && (cacheDir = (*FcStrListNext)(cacheDirs))) { jstr = (*env)->NewStringUTF(env, (const char*)cacheDir); JNU_CHECK_EXCEPTION(env); (*env)->SetObjectArrayElement(env, cacheDirArray, cnt++, jstr); } (*FcStrListDone)(cacheDirs); } } locale = (*env)->GetStringUTFChars(env, localeStr, 0); if (locale == NULL) { (*env)->ExceptionClear(env); JNU_ThrowOutOfMemoryError(env, "Could not create locale"); return; } arrlen = (*env)->GetArrayLength(env, fcCompFontArray); for (i=0; i<arrlen; i++) { FcFontSet* fontset; int fn, j, fontCount, nfonts; unsigned int minGlyphs; FcChar8 **family, **styleStr, **fullname, **file; jarray fcFontArr; fcCompFontObj = (*env)->GetObjectArrayElement(env, fcCompFontArray, i); fcNameStr = (jstring)((*env)->GetObjectField(env, fcCompFontObj, fcNameID)); fcName = (*env)->GetStringUTFChars(env, fcNameStr, 0); if (fcName == NULL) { continue; } pattern = (*FcNameParse)((FcChar8 *)fcName); if (pattern == NULL) { (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName); closeFontConfig(libfontconfig, JNI_FALSE); return; } /* locale may not usually be necessary as fontconfig appears to apply * this anyway based on the user's environment. However we want * to use the value of the JDK startup locale so this should take * care of it. */ if (locale != NULL) { (*FcPatternAddString)(pattern, FC_LANG, (unsigned char*)locale); } (*FcConfigSubstitute)(NULL, pattern, FcMatchPattern); (*FcDefaultSubstitute)(pattern); fontset = (*FcFontSort)(NULL, pattern, FcTrue, NULL, &result); if (fontset == NULL) { (*FcPatternDestroy)(pattern); (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName); closeFontConfig(libfontconfig, JNI_FALSE); return; } /* fontconfig returned us "nfonts". If we are just getting the * first font, we set nfont to zero. Otherwise we use "nfonts". * Next create separate C arrrays of length nfonts for family file etc. * Inspect the returned fonts and the ones we like (adds enough glyphs) * are added to the arrays and we increment 'fontCount'. */ nfonts = fontset->nfont; family = (FcChar8**)calloc(nfonts, sizeof(FcChar8*)); styleStr = (FcChar8**)calloc(nfonts, sizeof(FcChar8*)); fullname = (FcChar8**)calloc(nfonts, sizeof(FcChar8*)); file = (FcChar8**)calloc(nfonts, sizeof(FcChar8*)); if (family == NULL || styleStr == NULL || fullname == NULL || file == NULL) { if (family != NULL) { free(family); } if (styleStr != NULL) { free(styleStr); } if (fullname != NULL) { free(fullname); } if (file != NULL) { free(file); } (*FcPatternDestroy)(pattern); (*FcFontSetDestroy)(fontset); (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName); closeFontConfig(libfontconfig, JNI_FALSE); return; } fontCount = 0; minGlyphs = 20; if (debugMinGlyphsStr != NULL) { int val = minGlyphs; sscanf(debugMinGlyphsStr, "%5d", &val); if (val >= 0 && val <= 65536) { minGlyphs = val; } } FcCharSet *unionCharset = NULL; for (j=0; j<nfonts; j++) { FcPattern *fontPattern = fontset->fonts[j]; FcChar8 *fontformat; FcCharSet *charset = NULL; fontformat = NULL; (*FcPatternGetString)(fontPattern, FC_FONTFORMAT, 0, &fontformat); /* We only want TrueType fonts but some Linuxes still depend * on Type 1 fonts for some Locale support, so we'll allow * them there. */ if (fontformat != NULL && (strcmp((char*)fontformat, "TrueType") != 0) #if defined(__linux__) || defined(_AIX) && (strcmp((char*)fontformat, "Type 1") != 0) #endif ) { continue; } result = (*FcPatternGetCharSet)(fontPattern, FC_CHARSET, 0, &charset); if (result != FcResultMatch) { free(family); free(fullname); free(styleStr); free(file); (*FcPatternDestroy)(pattern); (*FcFontSetDestroy)(fontset); (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName); closeFontConfig(libfontconfig, JNI_FALSE); return; } /* We don't want 20 or 30 fonts, so once we hit 10 fonts, * then require that they really be adding value. Too many * adversely affects load time for minimal value-add. * This is still likely far more than we've had in the past. */ if (j==10) { minGlyphs = 50; } if (unionCharset == NULL) { unionCharset = charset; } else { if ((*FcCharSetSubtractCount)(charset, unionCharset) > minGlyphs) { unionCharset = (* FcCharSetUnion)(unionCharset, charset); } else { continue; } } fontCount++; // found a font we will use. (*FcPatternGetString)(fontPattern, FC_FILE, 0, &file[j]); (*FcPatternGetString)(fontPattern, FC_FAMILY, 0, &family[j]); (*FcPatternGetString)(fontPattern, FC_STYLE, 0, &styleStr[j]); (*FcPatternGetString)(fontPattern, FC_FULLNAME, 0, &fullname[j]); if (!includeFallbacks) { break; } if (fontCount == 254) { break; // CompositeFont will only use up to 254 slots from here. } } /* Once we get here 'fontCount' is the number of returned fonts * we actually want to use, so we create 'fcFontArr' of that length. * The non-null entries of "family[]" etc are those fonts. * Then loop again over all nfonts adding just those non-null ones * to 'fcFontArr'. If its null (we didn't want the font) * then we don't enter the main body. * So we should never get more than 'fontCount' entries. */ if (includeFallbacks) { fcFontArr = (*env)->NewObjectArray(env, fontCount, fcFontClass, NULL); (*env)->SetObjectField(env,fcCompFontObj, fcAllFontsID, fcFontArr); } fn=0; for (j=0;j<nfonts;j++) { if (family[j] != NULL) { jobject fcFont = (*env)->NewObject(env, fcFontClass, fcFontCons); jstr = (*env)->NewStringUTF(env, (const char*)family[j]); (*env)->SetObjectField(env, fcFont, familyNameID, jstr); if (file[j] != NULL) { jstr = (*env)->NewStringUTF(env, (const char*)file[j]); (*env)->SetObjectField(env, fcFont, fontFileID, jstr); } if (styleStr[j] != NULL) { jstr = (*env)->NewStringUTF(env, (const char*)styleStr[j]); (*env)->SetObjectField(env, fcFont, styleNameID, jstr); } if (fullname[j] != NULL) { jstr = (*env)->NewStringUTF(env, (const char*)fullname[j]); (*env)->SetObjectField(env, fcFont, fullNameID, jstr); } if (fn==0) { (*env)->SetObjectField(env, fcCompFontObj, fcFirstFontID, fcFont); } if (includeFallbacks) { (*env)->SetObjectArrayElement(env, fcFontArr, fn++,fcFont); } else { break; } } } (*env)->ReleaseStringUTFChars (env, fcNameStr, (const char*)fcName); (*FcFontSetDestroy)(fontset); (*FcPatternDestroy)(pattern); free(family); free(styleStr); free(fullname); free(file); } /* release resources and close the ".so" */ if (locale) { (*env)->ReleaseStringUTFChars (env, localeStr, (const char*)locale); } closeFontConfig(libfontconfig, JNI_TRUE); }
static void initFontIDs(JNIEnv *env) { jclass tmpClass; if (initialisedFontIDs) { return; } CHECK_NULL(tmpClass = (*env)->FindClass(env, "sun/font/TrueTypeFont")); CHECK_NULL(sunFontIDs.ttReadBlockMID = (*env)->GetMethodID(env, tmpClass, "readBlock", "(Ljava/nio/ByteBuffer;II)I")); CHECK_NULL(sunFontIDs.ttReadBytesMID = (*env)->GetMethodID(env, tmpClass, "readBytes", "(II)[B")); CHECK_NULL(tmpClass = (*env)->FindClass(env, "sun/font/Type1Font")); CHECK_NULL(sunFontIDs.readFileMID = (*env)->GetMethodID(env, tmpClass, "readFile", "(Ljava/nio/ByteBuffer;)V")); CHECK_NULL(tmpClass = (*env)->FindClass(env, "java/awt/geom/Point2D$Float")); sunFontIDs.pt2DFloatClass = (jclass)(*env)->NewGlobalRef(env, tmpClass); CHECK_NULL(sunFontIDs.pt2DFloatCtr = (*env)->GetMethodID(env, sunFontIDs.pt2DFloatClass, "<init>","(FF)V")); CHECK_NULL(sunFontIDs.xFID = (*env)->GetFieldID(env, sunFontIDs.pt2DFloatClass, "x", "F")); CHECK_NULL(sunFontIDs.yFID = (*env)->GetFieldID(env, sunFontIDs.pt2DFloatClass, "y", "F")); CHECK_NULL(tmpClass = (*env)->FindClass(env, "sun/font/StrikeMetrics")); CHECK_NULL(sunFontIDs.strikeMetricsClass = (jclass)(*env)->NewGlobalRef(env, tmpClass)); CHECK_NULL(sunFontIDs.strikeMetricsCtr = (*env)->GetMethodID(env, sunFontIDs.strikeMetricsClass, "<init>", "(FFFFFFFFFF)V")); CHECK_NULL(tmpClass = (*env)->FindClass(env, "java/awt/geom/Rectangle2D$Float")); sunFontIDs.rect2DFloatClass = (jclass)(*env)->NewGlobalRef(env, tmpClass); CHECK_NULL(sunFontIDs.rect2DFloatCtr = (*env)->GetMethodID(env, sunFontIDs.rect2DFloatClass, "<init>", "()V")); CHECK_NULL(sunFontIDs.rect2DFloatCtr4 = (*env)->GetMethodID(env, sunFontIDs.rect2DFloatClass, "<init>", "(FFFF)V")); CHECK_NULL(sunFontIDs.rectF2DX = (*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "x", "F")); CHECK_NULL(sunFontIDs.rectF2DY = (*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "y", "F")); CHECK_NULL(sunFontIDs.rectF2DWidth = (*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "width", "F")); CHECK_NULL(sunFontIDs.rectF2DHeight = (*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "height", "F")); CHECK_NULL(tmpClass = (*env)->FindClass(env, "java/awt/geom/GeneralPath")); sunFontIDs.gpClass = (jclass)(*env)->NewGlobalRef(env, tmpClass); CHECK_NULL(sunFontIDs.gpCtr = (*env)->GetMethodID(env, sunFontIDs.gpClass, "<init>", "(I[BI[FI)V")); CHECK_NULL(sunFontIDs.gpCtrEmpty = (*env)->GetMethodID(env, sunFontIDs.gpClass, "<init>", "()V")); CHECK_NULL(tmpClass = (*env)->FindClass(env, "sun/font/Font2D")); CHECK_NULL(sunFontIDs.f2dCharToGlyphMID = (*env)->GetMethodID(env, tmpClass, "charToGlyph", "(I)I")); CHECK_NULL(sunFontIDs.getMapperMID = (*env)->GetMethodID(env, tmpClass, "getMapper", "()Lsun/font/CharToGlyphMapper;")); CHECK_NULL(sunFontIDs.getTableBytesMID = (*env)->GetMethodID(env, tmpClass, "getTableBytes", "(I)[B")); CHECK_NULL(sunFontIDs.canDisplayMID = (*env)->GetMethodID(env, tmpClass, "canDisplay", "(C)Z")); CHECK_NULL(tmpClass = (*env)->FindClass(env, "sun/font/CharToGlyphMapper")); CHECK_NULL(sunFontIDs.charToGlyphMID = (*env)->GetMethodID(env, tmpClass, "charToGlyph", "(I)I")); CHECK_NULL(tmpClass = (*env)->FindClass(env, "sun/font/PhysicalStrike")); CHECK_NULL(sunFontIDs.getGlyphMetricsMID = (*env)->GetMethodID(env, tmpClass, "getGlyphMetrics", "(I)Ljava/awt/geom/Point2D$Float;")); CHECK_NULL(sunFontIDs.getGlyphPointMID = (*env)->GetMethodID(env, tmpClass, "getGlyphPoint", "(II)Ljava/awt/geom/Point2D$Float;")); CHECK_NULL(sunFontIDs.adjustPointMID = (*env)->GetMethodID(env, tmpClass, "adjustPoint", "(Ljava/awt/geom/Point2D$Float;)V")); CHECK_NULL(sunFontIDs.pScalerContextFID = (*env)->GetFieldID(env, tmpClass, "pScalerContext", "J")); CHECK_NULL(tmpClass = (*env)->FindClass(env, "sun/font/GlyphList")); CHECK_NULL(sunFontIDs.glyphListX = (*env)->GetFieldID(env, tmpClass, "x", "F")); CHECK_NULL(sunFontIDs.glyphListY = (*env)->GetFieldID(env, tmpClass, "y", "F")); CHECK_NULL(sunFontIDs.glyphListLen = (*env)->GetFieldID(env, tmpClass, "len", "I")); CHECK_NULL(sunFontIDs.glyphImages = (*env)->GetFieldID(env, tmpClass, "images", "[J")); CHECK_NULL(sunFontIDs.glyphListUsePos = (*env)->GetFieldID(env, tmpClass, "usePositions", "Z")); CHECK_NULL(sunFontIDs.glyphListPos = (*env)->GetFieldID(env, tmpClass, "positions", "[F")); CHECK_NULL(sunFontIDs.lcdRGBOrder = (*env)->GetFieldID(env, tmpClass, "lcdRGBOrder", "Z")); CHECK_NULL(sunFontIDs.lcdSubPixPos = (*env)->GetFieldID(env, tmpClass, "lcdSubPixPos", "Z")); initLCDGammaTables(); initialisedFontIDs = 1; }
// TODO: test: can create send failed without any data? if so need to // update API so that buffer can be null if no data. void handleSendFailed (JNIEnv* env, int fd, jobject resultContainerObj, struct sctp_send_failed *ssf, int read, jboolean isEOR, struct sockaddr* sap) { jobject bufferObj = NULL, resultObj, isaObj; char *addressP; struct sctp_sndrcvinfo *sri; int remaining, dataLength; /* the actual undelivered message data is directly after the ssf */ int dataOffset = sizeof(struct sctp_send_failed); sri = (struct sctp_sndrcvinfo*) &ssf->ssf_info; /* the number of bytes remaining to be read in the sctp_send_failed notif*/ remaining = ssf->ssf_length - read; /* the size of the actual undelivered message */ dataLength = ssf->ssf_length - dataOffset; /* retrieved address from sockaddr */ isaObj = SockAddrToInetSocketAddress(env, sap); /* data retrieved from sff_data */ if (dataLength > 0) { struct iovec iov[1]; struct msghdr msg[1]; int rv, alreadyRead; char *dataP = (char*) ssf; dataP += dataOffset; if ((addressP = malloc(dataLength)) == NULL) { JNU_ThrowOutOfMemoryError(env, "handleSendFailed"); return; } memset(msg, 0, sizeof (*msg)); msg->msg_iov = iov; msg->msg_iovlen = 1; bufferObj = (*env)->NewDirectByteBuffer(env, addressP, dataLength); CHECK_NULL(bufferObj); alreadyRead = read - dataOffset; if (alreadyRead > 0) { memcpy(addressP, /*ssf->ssf_data*/ dataP, alreadyRead); iov->iov_base = addressP + alreadyRead; iov->iov_len = dataLength - alreadyRead; } else { iov->iov_base = addressP; iov->iov_len = dataLength; } if (remaining > 0) { if ((rv = recvmsg(fd, msg, 0)) < 0) { handleSocketError(env, errno); return; } if (rv != (dataLength - alreadyRead) || !(msg->msg_flags & MSG_EOR)) { //TODO: assert false: "should not reach here"; return; } // TODO: Set and document (in API) buffers position. } } /* create SctpSendFailed */ resultObj = (*env)->NewObject(env, ssf_class, ssf_ctrID, ssf->ssf_assoc_id, isaObj, bufferObj, ssf->ssf_error, sri->sinfo_stream); CHECK_NULL(resultObj); (*env)->SetObjectField(env, resultContainerObj, src_valueID, resultObj); (*env)->SetIntField(env, resultContainerObj, src_typeID, sun_nio_ch_SctpResultContainer_SEND_FAILED); }
static int l_esc_read (GPPort *p, unsigned char *c) { CHECK_NULL (p && c); CHECK (gp_port_read (p, c, 1)); /* * STX, ETX, ENQ, ACK, XOFF, XON, NACK, and ETB have to be masked by * ESC. If we receive one of those (except ETX and ETB) without mask, * we will not report an error, as it will be recovered automatically * later. If we receive ETX or ETB, we reached the end of the packet * and report a transmission error, so that the error can be * recovered. * If the camera sends us ESC (the mask), we will not count this byte * and read a second one. This will be reverted and processed. It * then must be one of STX, ETX, ENQ, ACK, XOFF, XON, NACK, ETB, or * ESC. As before, if it is not one of those, we'll not report an * error, as it will be recovered automatically later. */ /* The HP PhotoSmart does not escape every special code, only * some and it gets confused if we do this checks. By relaxing * these, it now downloads images etc. */ #ifndef LESSER_ESCAPES if ((*c == STX ) || (*c == ETX) || (*c == ENQ ) || (*c == ACK) || (*c == XOFF) || (*c == XON) || (*c == NACK) || (*c == ETB)) { #else /* LESSER_ESCAPES */ if ((*c == STX ) || (*c == XOFF) || (*c == XON)) { #endif /* LESSER_ESCAPES */ GP_DEBUG ("Wrong ESC masking!"); if ((*c == ETX) || (*c == ETB)) return (-1); } else if (*c == ESC) { CHECK (gp_port_read (p, c, 1)); *c = (~*c & 0xff); if ((*c != STX ) && (*c != ETX ) && (*c != ENQ) && (*c != ACK ) && (*c != XOFF) && (*c != XON) && (*c != NACK) && (*c != ETB ) && (*c != ESC)) GP_DEBUG ("Wrong ESC masking!"); } return (0); } static int l_send (GPPort *p, GPFsErr *context, unsigned char *send_buffer, unsigned int send_buffer_size) { unsigned char c; unsigned char checksum; /**********************************************************************/ /* sb: A pointer to the buffer that we will send. */ /* sbs: Its size. */ /**********************************************************************/ unsigned char *sb; unsigned int sbs; int i = 0; CHECK_NULL (p && send_buffer); /* We need to ping the camera first */ CHECK (l_ping (p, context)); /********************************************************/ /* We will write: */ /* - STX */ /* - low order byte of (send_buffer_size + 5) */ /* - high order byte of (send_buffer_size + 5) */ /* - 'send_buffer_size' bytes data plus ESC quotes */ /* - ETX */ /* - 1 byte for checksum plus ESC quotes */ /* */ /* The checksum covers all bytes after STX and before */ /* the checksum byte(s). */ /********************************************************/ sbs = send_buffer_size + 5; sb = malloc (sizeof (char) * sbs); sb[0] = STX; sb[1] = send_buffer_size; sb[2] = send_buffer_size >> 8; checksum = sb[1]; checksum += sb[2]; for (i = 3; i < (sbs - 2); i++) { checksum += *send_buffer; if ( (*send_buffer == STX ) || (*send_buffer == ETX ) || (*send_buffer == ENQ ) || (*send_buffer == ACK ) || (*send_buffer == XOFF) || (*send_buffer == XON ) || (*send_buffer == NACK) || (*send_buffer == ETB ) || (*send_buffer == ESC )) { sb = realloc (sb, ++sbs * sizeof (char)); sb[ i] = ESC; sb[++i] = ~*send_buffer; } else sb[ i] = *send_buffer; send_buffer++; } sb[sbs - 2] = ETX; checksum += ETX; if ( (checksum == STX ) || (checksum == ETX ) || (checksum == ENQ ) || (checksum == ACK ) || (checksum == XOFF) || (checksum == XON ) || (checksum == NACK) || (checksum == ETB ) || (checksum == ESC )) { sb = realloc (sb, ++sbs * sizeof (char)); sb[sbs - 2] = ESC; sb[sbs - 1] = ~checksum; } else sb[sbs - 1] = checksum; for (i = 0; ; i++) { /* Write data as above. */ CHECK_FREE (gp_port_write (p, sb, sbs), sb); CHECK_FREE (gp_port_read (p, &c, 1), sb); switch (c) { case ACK: /* ACK received. We can proceed. */ free (sb); /* Write EOT. */ c = EOT; CHECK (gp_port_write (p, &c, 1)); return (0); case NACK: /* NACK received. We'll try up to three times. */ if (i == 2) { free (sb); return (-1); } else break; default: /* Should not happen. */ return (-1); } } }
static unsigned int is_valid_list_id(unsigned int list_id) { pgeneric_list_t p_list = get_list_from_allotted_list(list_id); return CHECK_NULL(p_list) ? 0 : 1; }
static int size(unsigned int list_id) { pgeneric_list_t p_list = get_list_from_allotted_list(list_id); return CHECK_NULL(p_list) ? -1 : p_list->node_count; }
static void action_about (GtkAction *action, gpointer callback_data) { GtkamMain *m = GTKAM_MAIN (callback_data); GtkWidget *d; const gchar *comments = N_("gtkam is a program that lets you download\n" "images from many digital cameras. It uses\n" "libgphoto2. More info is available at\n" "http://www.gphoto.org.\n" "\n" "Enjoy the wonderful world of gphoto!"); #ifdef HAVE_GNOME GtkWidget *w; const gchar *authors[] = { "Scott Fritzinger <*****@*****.**>", "Lutz Mueller <*****@*****.**>", _("Many others"), NULL }; const gchar *documenters[] = { "Michael J. Rensing <*****@*****.**>", NULL }; const gchar *translator_credits = "Keld Simonsen <*****@*****.**>\n" "Marcus Meissner <*****@*****.**>\n" "Fabian Mandelbaum <*****@*****.**>\n" "Kjartan Maraas <*****@*****.**>\n" "Andraz Tori <*****@*****.**>"; GdkPixbuf *p; #else gchar *buf; #endif gchar *gcomments = NULL; int n; for (n = 0; module_versions[n].name != NULL; n++) { gchar *features; const char **v = NULL; char *name = module_versions[n].name; GPVersionFunc func = module_versions[n].version_func; CHECK_NULL (name); CHECK_NULL (func); v = func(GP_VERSION_SHORT); CHECK_NULL (v); CHECK_NULL (v[0]); CHECK_NULL (v[1]); /* FIXME: implicit conversion from char to gchar */ features = g_strjoinv(", ", &v[1]); if (gcomments == NULL) { gcomments = g_strdup_printf(_("%s\n\n%s %s with options:\n %s\n"), _(comments), name, v[0], features); } else { gchar *old = gcomments; gcomments = g_strdup_printf(_("%s\n%s %s with options:\n %s\n"), gcomments, name, v[0], features); free(old); } free(features); } #ifdef HAVE_GNOME p = gdk_pixbuf_new_from_file (IMAGE_DIR "/gtkam-camera.png", NULL); d = gnome_about_new (PACKAGE, VERSION, "GPL", gcomments, authors, documenters, translator_credits, p); g_object_unref (G_OBJECT (p)); w = gnome_href_new ("http://www.gphoto.org", "http://www.gphoto.org"); gtk_widget_show (w); gtk_box_pack_end (GTK_BOX (GTK_DIALOG (d)->vbox), w, FALSE, FALSE, 0); #else buf = g_strdup_printf ("%s-%s\n\n%s", PACKAGE, VERSION, gcomments); d = gtkam_close_new (buf); g_free (buf); #endif gtk_window_set_transient_for (GTK_WINDOW (d), GTK_WINDOW (m)); gtk_widget_show (d); /* FIXME free(gcomments); */ }
const IR::Type_Struct* ReplacementMap::getReplacement(const IR::Type_Tuple* tt) { auto st = convertType(tt)->to<IR::Type_Struct>(); CHECK_NULL(st); replacement.emplace(tt, st); return st; }
/* transaction time: 0.5ms for 16 data bytes @6MHz, 1kB chunks */ int lgw_spi_wb(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, uint8_t address, uint8_t *data, uint16_t size) { struct mpsse_context *mpsse = spi_target; uint8_t command[2]; uint8_t command_size; uint8_t *out_buf = NULL; int size_to_do, buf_size, chunk_size, offset; int a=0, b=0, c=0; int i; /* check input parameters */ CHECK_NULL(spi_target); if ((address & 0x80) != 0) { DEBUG_MSG("WARNING: SPI address > 127\n"); } CHECK_NULL(data); if (size == 0) { DEBUG_MSG("ERROR: BURST OF NULL LENGTH\n"); return LGW_SPI_ERROR; } /* prepare command byte */ if (spi_mux_mode == LGW_SPI_MUX_MODE1) { command[0] = spi_mux_target; command[1] = WRITE_ACCESS | (address & 0x7F); command_size = 2; } else { command[0] = WRITE_ACCESS | (address & 0x7F); command_size = 1; } size_to_do = size + command_size; /* add a byte for the address */ /* allocate data buffer */ buf_size = (size_to_do < LGW_BURST_CHUNK) ? size_to_do : LGW_BURST_CHUNK; out_buf = malloc(buf_size); if (out_buf == NULL) { DEBUG_MSG("ERROR: MALLOC FAIL\n"); return LGW_SPI_ERROR; } /* start MPSSE transaction */ a = Start(mpsse); for (i=0; size_to_do > 0; ++i) { chunk_size = (size_to_do < LGW_BURST_CHUNK) ? size_to_do : LGW_BURST_CHUNK; if (i == 0) { /* first chunk, need to append the address */ out_buf[0] = command[0]; memcpy(out_buf+1, data, chunk_size-1); } else { /* following chunks, just copy the data */ offset = (i * LGW_BURST_CHUNK) - 1; memcpy(out_buf, data + offset, chunk_size); } b = FastWrite(mpsse, (char *)out_buf, chunk_size); size_to_do -= chunk_size; /* subtract the quantity of data already transferred */ } c = Stop(mpsse); /* deallocate data buffer */ free(out_buf); /* determine return code (only the last FastWrite is checked) */ if ((a != MPSSE_OK) || (b != MPSSE_OK) || (c != MPSSE_OK)) { DEBUG_MSG("ERROR: SPI BURST WRITE FAILURE\n"); return LGW_SPI_ERROR; } else { DEBUG_MSG("Note: SPI burst write success\n"); return LGW_SPI_SUCCESS; } }
/* Original function returned enum ErrCode */ int tl880_audio_set_crossfade(struct tl880_dev *tl880dev, s32 a, s32 b, u8 c, u8 d, u8 e, u8 f, u8 g, u8 h) { u32 reg305c; u32 reg3060; u32 reg3064; u32 reg3068; u32 reg306c; u32 reg3070; u32 reg3074; u32 reg3078; u32 reg307c; if(CHECK_NULL(tl880dev)) { return -1; } switch(a) { case 0: if(b == 0) { reg305c = tl880_read_register(tl880dev, 0x305c); reg3060 = tl880_read_register(tl880dev, 0x3060); reg3064 = tl880_read_register(tl880dev, 0x3064); tl880_write_register(tl880dev, 0x305c, (reg305c & 0xffff0000) | (d << 8) | c); tl880_write_register(tl880dev, 0x3060, (reg3060 & 0xffff0000) | (f << 8) | e); tl880_write_register(tl880dev, 0x3064, (reg3064 & 0xffff0000) | (h << 8) | g); break; } if(b != 1) { break; } reg305c = tl880_read_register(tl880dev, 0x305c); reg3060 = tl880_read_register(tl880dev, 0x3060); reg3064 = tl880_read_register(tl880dev, 0x3064); tl880_write_register(tl880dev, 0x305c, (d << 24) | (c << 16) | (reg305c & 0xffff)); tl880_write_register(tl880dev, 0x3060, (f << 24) | (e << 16) | (reg3060 & 0xffff)); tl880_write_register(tl880dev, 0x3064, (h << 24) | (g << 16) | (reg3064 & 0xffff)); break; case 1: if(b == 0) { reg3068 = tl880_read_register(tl880dev, 0x3068); reg306c = tl880_read_register(tl880dev, 0x306c); reg3070 = tl880_read_register(tl880dev, 0x3070); tl880_write_register(tl880dev, 0x3068, (reg3068 & 0xffff0000) | (d << 8) | c); tl880_write_register(tl880dev, 0x306c, (reg306c & 0xffff0000) | (f << 8) | e); tl880_write_register(tl880dev, 0x3070, (reg3070 & 0xffff0000) | (h << 8) | g); break; } if(b != 1) { break; } reg3068 = tl880_read_register(tl880dev, 0x3068); reg306c = tl880_read_register(tl880dev, 0x306c); reg3070 = tl880_read_register(tl880dev, 0x3070); tl880_write_register(tl880dev, 0x3068, (d << 24) | (c << 16) | (reg3068 & 0xffff)); tl880_write_register(tl880dev, 0x306c, (f << 24) | (e << 16) | (reg306c & 0xffff)); tl880_write_register(tl880dev, 0x3070, (h << 24) | (g << 16) | (reg3070 & 0xffff)); break; case 2: if(b == 0) { reg3074 = tl880_read_register(tl880dev, 0x3074); reg3078 = tl880_read_register(tl880dev, 0x3078); reg307c = tl880_read_register(tl880dev, 0x307c); tl880_write_register(tl880dev, 0x3074, (reg3074 & 0xffff0000) | (d << 8) | c); tl880_write_register(tl880dev, 0x3078, (reg3078 & 0xffff0000) | (f << 8) | e); tl880_write_register(tl880dev, 0x307c, (reg307c & 0xffff0000) | (h << 8) | g); break; } if(b != 1) { break; } reg3074 = tl880_read_register(tl880dev, 0x3074); reg3078 = tl880_read_register(tl880dev, 0x3078); reg307c = tl880_read_register(tl880dev, 0x307C); tl880_write_register(tl880dev, 0x3074, ((d << 24) | (c << 16)) | (reg3074 & 0xffff)); tl880_write_register(tl880dev, 0x3078, (f << 24) | (e << 16) | (reg3078 & 0xffff)); tl880_write_register(tl880dev, 0x307C, (h << 24) | (g << 16) | (reg307c & 0xffff)); break; default: break; } return 0; }
void print_idmapdstate(void) { int i, j; idmap_pg_config_t *pgcfg; idmap_trustedforest_t *tf; RDLOCK_CONFIG(); if (_idmapdstate.cfg == NULL) { idmapdlog(LOG_INFO, "Null configuration"); UNLOCK_CONFIG(); return; } pgcfg = &_idmapdstate.cfg->pgcfg; idmapdlog(LOG_DEBUG, "list_size_limit=%llu", pgcfg->list_size_limit); idmapdlog(LOG_DEBUG, "default_domain=%s", CHECK_NULL(pgcfg->default_domain)); idmapdlog(LOG_DEBUG, "domain_name=%s", CHECK_NULL(pgcfg->domain_name)); idmapdlog(LOG_DEBUG, "machine_sid=%s", CHECK_NULL(pgcfg->machine_sid)); if (pgcfg->domain_controller == NULL || pgcfg->domain_controller[0].host[0] == '\0') { idmapdlog(LOG_DEBUG, "No domain controllers known"); } else { for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++) idmapdlog(LOG_DEBUG, "domain_controller=%s port=%d", pgcfg->domain_controller[i].host, pgcfg->domain_controller[i].port); } idmapdlog(LOG_DEBUG, "forest_name=%s", CHECK_NULL(pgcfg->forest_name)); idmapdlog(LOG_DEBUG, "site_name=%s", CHECK_NULL(pgcfg->site_name)); if (pgcfg->global_catalog == NULL || pgcfg->global_catalog[0].host[0] == '\0') { idmapdlog(LOG_DEBUG, "No global catalog servers known"); } else { for (i = 0; pgcfg->global_catalog[i].host[0] != '\0'; i++) idmapdlog(LOG_DEBUG, "global_catalog=%s port=%d", pgcfg->global_catalog[i].host, pgcfg->global_catalog[i].port); } if (pgcfg->domains_in_forest == NULL || pgcfg->domains_in_forest[0].domain[0] == '\0') { idmapdlog(LOG_DEBUG, "No domains in forest %s known", CHECK_NULL(pgcfg->forest_name)); } else { for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0'; i++) idmapdlog(LOG_DEBUG, "domains in forest %s = %s", CHECK_NULL(pgcfg->forest_name), pgcfg->domains_in_forest[i].domain); } if (pgcfg->trusted_domains == NULL || pgcfg->trusted_domains[0].domain[0] == '\0') { idmapdlog(LOG_DEBUG, "No trusted domains known"); } else { for (i = 0; pgcfg->trusted_domains[i].domain[0] != '\0'; i++) idmapdlog(LOG_DEBUG, "trusted domain = %s", pgcfg->trusted_domains[i].domain); } for (i = 0; i < pgcfg->num_trusted_forests; i++) { tf = &pgcfg->trusted_forests[i]; for (j = 0; tf->global_catalog[j].host[0] != '\0'; j++) idmapdlog(LOG_DEBUG, "trusted forest %s global_catalog=%s port=%d", tf->forest_name, tf->global_catalog[j].host, tf->global_catalog[j].port); for (j = 0; tf->domains_in_forest[j].domain[0] != '\0'; j++) { if (tf->domains_in_forest[j].trusted) { idmapdlog(LOG_DEBUG, "trusted forest %s domain=%s", tf->forest_name, tf->domains_in_forest[j].domain); } } } idmapdlog(LOG_DEBUG, "directory_based_mapping=%s", enum_lookup(pgcfg->directory_based_mapping, directory_mapping_map)); idmapdlog(LOG_DEBUG, "ad_unixuser_attr=%s", CHECK_NULL(pgcfg->ad_unixuser_attr)); idmapdlog(LOG_DEBUG, "ad_unixgroup_attr=%s", CHECK_NULL(pgcfg->ad_unixgroup_attr)); idmapdlog(LOG_DEBUG, "nldap_winname_attr=%s", CHECK_NULL(pgcfg->nldap_winname_attr)); UNLOCK_CONFIG(); }
/** * \brief Configure a port * * Makes a port functional by passing in the necessary path * information (from the serial:/dev/ttyS0 or similar variables). * After calling this function, you can access the port using for * example gp_port_open(). * * \param port a GPPort * \param info the GPPortInfo to set * * \return a gphoto2 error code **/ int gp_port_set_info (GPPort *port, GPPortInfo info) { GPPortLibraryOperations ops_func; CHECK_NULL (port); if (port->pc->info.name) free (port->pc->info.name); port->pc->info.name = strdup (info->name); if (port->pc->info.path) free (port->pc->info.path); port->pc->info.path = strdup (info->path); port->pc->info.type = info->type; if (port->pc->info.library_filename) free (port->pc->info.library_filename); port->pc->info.library_filename = strdup (info->library_filename); port->type = info->type; /* Clean up */ if (port->pc->ops) { gp_port_exit (port); free (port->pc->ops); port->pc->ops = NULL; } if (port->pc->lh) { lt_dlclose (port->pc->lh); lt_dlexit (); } lt_dlinit (); port->pc->lh = lt_dlopenext (info->library_filename); if (!port->pc->lh) { gp_log (GP_LOG_ERROR, "gphoto2-port", _("Could not load " "'%s' ('%s')."), info->library_filename, lt_dlerror ()); lt_dlexit (); return (GP_ERROR_LIBRARY); } /* Load the operations */ ops_func = lt_dlsym (port->pc->lh, "gp_port_library_operations"); if (!ops_func) { gp_log (GP_LOG_ERROR, "gphoto2-port", _("Could not find " "'gp_port_library_operations' in '%s' ('%s')"), info->library_filename, lt_dlerror ()); lt_dlclose (port->pc->lh); lt_dlexit (); port->pc->lh = NULL; return (GP_ERROR_LIBRARY); } port->pc->ops = ops_func (); gp_port_init (port); /* Initialize the settings to some default ones */ switch (info->type) { case GP_PORT_SERIAL: port->settings.serial.speed = 0; port->settings.serial.bits = 8; port->settings.serial.parity = 0; port->settings.serial.stopbits = 1; gp_port_set_timeout (port, 500); break; case GP_PORT_USB: strncpy (port->settings.usb.port, info->path, sizeof (port->settings.usb.port)); port->settings.usb.inep = -1; port->settings.usb.outep = -1; port->settings.usb.config = -1; port->settings.usb.interface = 0; port->settings.usb.altsetting = -1; gp_port_set_timeout (port, 5000); break; case GP_PORT_USB_DISK_DIRECT: snprintf(port->settings.usbdiskdirect.path, sizeof(port->settings.usbdiskdirect.path), "%s", strchr(info->path, ':') + 1); break; case GP_PORT_USB_SCSI: snprintf(port->settings.usbscsi.path, sizeof(port->settings.usbscsi.path), "%s", strchr(info->path, ':') + 1); break; default: /* Nothing in here */ break; } gp_port_set_settings (port, port->settings); return (GP_OK); }
void GREX::cmd(const string&key,void*val){ if(false){ }else if(key=="initialized"){ CHECK_NULL(val,key); *static_cast<int*>(val)=initialized; }else if(key=="setMPIIntracomm"){ CHECK_NOTINIT(initialized,key); intracomm.Set_comm(val); }else if(key=="setMPIIntercomm"){ CHECK_NOTINIT(initialized,key); intercomm.Set_comm(val); plumedMain.multi_sim_comm.Set_comm(val); }else if(key=="setMPIFIntracomm"){ CHECK_NOTINIT(initialized,key); intracomm.Set_fcomm(val); }else if(key=="setMPIFIntercomm"){ CHECK_NOTINIT(initialized,key); intercomm.Set_fcomm(val); plumedMain.multi_sim_comm.Set_fcomm(val); }else if(key=="init"){ CHECK_NOTINIT(initialized,key); initialized=true; std::string s; // note that for PEs!=root this is automatically 0 (comm defaults to MPI_COMM_SELF) myreplica=intercomm.Get_rank(); intracomm.Sum(myreplica); Tools::convert(myreplica,s); plumedMain.setSuffix("."+s); }else if(key=="prepare"){ CHECK_INIT(initialized,key); if(intracomm.Get_rank()==0) return; intracomm.Bcast(partner,0); calculate(); }else if(key=="setPartner"){ CHECK_INIT(initialized,key); partner=*static_cast<int*>(val); }else if(key=="savePositions"){ CHECK_INIT(initialized,key); savePositions(); }else if(key=="calculate"){ CHECK_INIT(initialized,key); if(intracomm.Get_rank()!=0) return; intracomm.Bcast(partner,0); calculate(); }else if(key=="getLocalDeltaBias"){ CHECK_INIT(initialized,key); CHECK_NULL(val,key); double x=localDeltaBias/(atoms.getMDUnits().getEnergy()/atoms.getUnits().getEnergy()); atoms.double2MD(x,val); }else if(key=="cacheLocalUNow"){ CHECK_INIT(initialized,key); CHECK_NULL(val,key); double x; atoms.MD2double(val,x); localUNow=x*(atoms.getMDUnits().getEnergy()/atoms.getUnits().getEnergy()); intracomm.Sum(localUNow); }else if(key=="cacheLocalUSwap"){ CHECK_INIT(initialized,key); CHECK_NULL(val,key); double x; atoms.MD2double(val,x); localUSwap=x*(atoms.getMDUnits().getEnergy()/atoms.getUnits().getEnergy()); intracomm.Sum(localUSwap); }else if(key=="getForeignDeltaBias"){ CHECK_INIT(initialized,key); CHECK_NULL(val,key); double x=foreignDeltaBias/(atoms.getMDUnits().getEnergy()/atoms.getUnits().getEnergy()); atoms.double2MD(x,val); }else if(key=="shareAllDeltaBias"){ CHECK_INIT(initialized,key); if(intracomm.Get_rank()!=0) return; allDeltaBias.assign(intercomm.Get_size(),0.0); allDeltaBias[intercomm.Get_rank()]=localDeltaBias; intercomm.Sum(allDeltaBias); }else{ // multi word commands std::vector<std::string> words=Tools::getWords(key); int nw=words.size(); if(false){ } else if(nw==2 && words[0]=="getDeltaBias"){ CHECK_INIT(initialized,key); CHECK_NULL(val,key); plumed_massert(allDeltaBias.size()==static_cast<unsigned>(intercomm.Get_size()), "to retrieve bias with cmd(\"GREX getDeltaBias\"), first share it with cmd(\"GREX shareAllDeltaBias\")"); unsigned rep; Tools::convert(words[1],rep); plumed_massert(rep<allDeltaBias.size(),"replica index passed to cmd(\"GREX getDeltaBias\") is out of range"); double d=allDeltaBias[rep]/(atoms.getMDUnits().getEnergy()/atoms.getUnits().getEnergy()); atoms.double2MD(d,val); } else{ plumed_merror("cannot interpret cmd(\"GREX " + key + "\"). check plumed developers manual to see the available commands."); }; }; }
krb5_error_code krb5_ldap_put_principal(krb5_context context, krb5_db_entry *entry, char **db_args) { int l=0, kerberos_principal_object_type=0; krb5_error_code st=0, tempst=0; LDAP *ld=NULL; LDAPMessage *result=NULL, *ent=NULL; char *user=NULL, *subtree=NULL, *principal_dn=NULL; char **values=NULL, *strval[10]={NULL}, errbuf[1024]; char *filtuser=NULL; struct berval **bersecretkey=NULL; LDAPMod **mods=NULL; krb5_boolean create_standalone_prinicipal=FALSE; krb5_boolean krb_identity_exists=FALSE, establish_links=FALSE; char *standalone_principal_dn=NULL; krb5_tl_data *tl_data=NULL; krb5_key_data **keys=NULL; kdb5_dal_handle *dal_handle=NULL; krb5_ldap_context *ldap_context=NULL; krb5_ldap_server_handle *ldap_server_handle=NULL; osa_princ_ent_rec princ_ent; xargs_t xargs = {0}; char *polname = NULL; OPERATION optype; krb5_boolean found_entry = FALSE; /* Clear the global error string */ krb5_clear_error_message(context); SETUP_CONTEXT(); if (ldap_context->lrparams == NULL || ldap_context->container_dn == NULL) return EINVAL; /* get ldap handle */ GET_HANDLE(); if (is_principal_in_realm(ldap_context, entry->princ) != 0) { st = EINVAL; krb5_set_error_message(context, st, _("Principal does not belong to " "the default realm")); goto cleanup; } /* get the principal information to act on */ if (((st=krb5_unparse_name(context, entry->princ, &user)) != 0) || ((st=krb5_ldap_unparse_principal_name(user)) != 0)) goto cleanup; filtuser = ldap_filter_correct(user); if (filtuser == NULL) { st = ENOMEM; goto cleanup; } /* Identity the type of operation, it can be * add principal or modify principal. * hack if the entry->mask has KRB_PRINCIPAL flag set * then it is a add operation */ if (entry->mask & KADM5_PRINCIPAL) optype = ADD_PRINCIPAL; else optype = MODIFY_PRINCIPAL; if (((st=krb5_get_princ_type(context, entry, &kerberos_principal_object_type)) != 0) || ((st=krb5_get_userdn(context, entry, &principal_dn)) != 0)) goto cleanup; if ((st=process_db_args(context, db_args, &xargs, optype)) != 0) goto cleanup; if (entry->mask & KADM5_LOAD) { unsigned int tree = 0, ntrees = 0; int numlentries = 0; char **subtreelist = NULL, *filter = NULL; /* A load operation is special, will do a mix-in (add krbprinc * attrs to a non-krb object entry) if an object exists with a * matching krbprincipalname attribute so try to find existing * object and set principal_dn. This assumes that the * krbprincipalname attribute is unique (only one object entry has * a particular krbprincipalname attribute). */ if (asprintf(&filter, FILTER"%s))", filtuser) < 0) { filter = NULL; st = ENOMEM; goto cleanup; } /* get the current subtree list */ if ((st = krb5_get_subtree_info(ldap_context, &subtreelist, &ntrees)) != 0) goto cleanup; found_entry = FALSE; /* search for entry with matching krbprincipalname attribute */ for (tree = 0; found_entry == FALSE && tree < ntrees; ++tree) { result = NULL; if (principal_dn == NULL) { LDAP_SEARCH_1(subtreelist[tree], ldap_context->lrparams->search_scope, filter, principal_attributes, IGNORE_STATUS); } else { /* just look for entry with principal_dn */ LDAP_SEARCH_1(principal_dn, LDAP_SCOPE_BASE, filter, principal_attributes, IGNORE_STATUS); } if (st == LDAP_SUCCESS) { numlentries = ldap_count_entries(ld, result); if (numlentries > 1) { ldap_msgfree(result); free(filter); st = EINVAL; krb5_set_error_message(context, st, _("operation can not continue, " "more than one entry with " "principal name \"%s\" found"), user); goto cleanup; } else if (numlentries == 1) { found_entry = TRUE; if (principal_dn == NULL) { ent = ldap_first_entry(ld, result); if (ent != NULL) { /* setting principal_dn will cause that entry to be modified further down */ if ((principal_dn = ldap_get_dn(ld, ent)) == NULL) { ldap_get_option (ld, LDAP_OPT_RESULT_CODE, &st); st = set_ldap_error (context, st, 0); ldap_msgfree(result); free(filter); goto cleanup; } } } } if (result) ldap_msgfree(result); } else if (st != LDAP_NO_SUCH_OBJECT) { /* could not perform search, return with failure */ st = set_ldap_error (context, st, 0); free(filter); goto cleanup; } /* * If it isn't found then assume a standalone princ entry is to * be created. */ } /* end for (tree = 0; principal_dn == ... */ free(filter); if (found_entry == FALSE && principal_dn != NULL) { /* * if principal_dn is null then there is code further down to * deal with setting standalone_principal_dn. Also note that * this will set create_standalone_prinicipal true for * non-mix-in entries which is okay if loading from a dump. */ create_standalone_prinicipal = TRUE; standalone_principal_dn = strdup(principal_dn); CHECK_NULL(standalone_principal_dn); } } /* end if (entry->mask & KADM5_LOAD */ /* time to generate the DN information with the help of * containerdn, principalcontainerreference or * realmcontainerdn information */ if (principal_dn == NULL && xargs.dn == NULL) { /* creation of standalone principal */ /* get the subtree information */ if (entry->princ->length == 2 && entry->princ->data[0].length == strlen("krbtgt") && strncmp(entry->princ->data[0].data, "krbtgt", entry->princ->data[0].length) == 0) { /* if the principal is a inter-realm principal, always created in the realm container */ subtree = strdup(ldap_context->lrparams->realmdn); } else if (xargs.containerdn) { if ((st=checkattributevalue(ld, xargs.containerdn, NULL, NULL, NULL)) != 0) { if (st == KRB5_KDB_NOENTRY || st == KRB5_KDB_CONSTRAINT_VIOLATION) { int ost = st; st = EINVAL; snprintf(errbuf, sizeof(errbuf), _("'%s' not found: "), xargs.containerdn); prepend_err_str(context, errbuf, st, ost); } goto cleanup; } subtree = strdup(xargs.containerdn); } else if (ldap_context->lrparams->containerref && strlen(ldap_context->lrparams->containerref) != 0) { /* * Here the subtree should be changed with * principalcontainerreference attribute value */ subtree = strdup(ldap_context->lrparams->containerref); } else { subtree = strdup(ldap_context->lrparams->realmdn); } CHECK_NULL(subtree); if (asprintf(&standalone_principal_dn, "krbprincipalname=%s,%s", filtuser, subtree) < 0) standalone_principal_dn = NULL; CHECK_NULL(standalone_principal_dn); /* * free subtree when you are done using the subtree * set the boolean create_standalone_prinicipal to TRUE */ create_standalone_prinicipal = TRUE; free(subtree); subtree = NULL; } /* * If the DN information is presented by the user, time to * validate the input to ensure that the DN falls under * any of the subtrees */ if (xargs.dn_from_kbd == TRUE) { /* make sure the DN falls in the subtree */ unsigned int tre=0, ntrees=0; int dnlen=0, subtreelen=0; char **subtreelist=NULL; char *dn=NULL; krb5_boolean outofsubtree=TRUE; if (xargs.dn != NULL) { dn = xargs.dn; } else if (xargs.linkdn != NULL) { dn = xargs.linkdn; } else if (standalone_principal_dn != NULL) { /* * Even though the standalone_principal_dn is constructed * within this function, there is the containerdn input * from the user that can become part of the it. */ dn = standalone_principal_dn; } /* get the current subtree list */ if ((st = krb5_get_subtree_info(ldap_context, &subtreelist, &ntrees)) != 0) goto cleanup; for (tre=0; tre<ntrees; ++tre) { if (subtreelist[tre] == NULL || strlen(subtreelist[tre]) == 0) { outofsubtree = FALSE; break; } else { dnlen = strlen (dn); subtreelen = strlen(subtreelist[tre]); if ((dnlen >= subtreelen) && (strcasecmp((dn + dnlen - subtreelen), subtreelist[tre]) == 0)) { outofsubtree = FALSE; break; } } } for (tre=0; tre < ntrees; ++tre) { free(subtreelist[tre]); } if (outofsubtree == TRUE) { st = EINVAL; krb5_set_error_message(context, st, _("DN is out of the realm subtree")); goto cleanup; } /* * dn value will be set either by dn, linkdn or the standalone_principal_dn * In the first 2 cases, the dn should be existing and in the last case we * are supposed to create the ldap object. so the below should not be * executed for the last case. */ if (standalone_principal_dn == NULL) { /* * If the ldap object is missing, this results in an error. */ /* * Search for krbprincipalname attribute here. * This is to find if a kerberos identity is already present * on the ldap object, in which case adding a kerberos identity * on the ldap object should result in an error. */ char *attributes[]={"krbticketpolicyreference", "krbprincipalname", NULL}; LDAP_SEARCH_1(dn, LDAP_SCOPE_BASE, 0, attributes, IGNORE_STATUS); if (st == LDAP_SUCCESS) { ent = ldap_first_entry(ld, result); if (ent != NULL) { if ((values=ldap_get_values(ld, ent, "krbticketpolicyreference")) != NULL) { ldap_value_free(values); } if ((values=ldap_get_values(ld, ent, "krbprincipalname")) != NULL) { krb_identity_exists = TRUE; ldap_value_free(values); } } ldap_msgfree(result); } else { st = set_ldap_error(context, st, OP_SEARCH); goto cleanup; } } } /* * If xargs.dn is set then the request is to add a * kerberos principal on a ldap object, but if * there is one already on the ldap object this * should result in an error. */ if (xargs.dn != NULL && krb_identity_exists == TRUE) { st = EINVAL; snprintf(errbuf, sizeof(errbuf), _("ldap object is already kerberized")); krb5_set_error_message(context, st, "%s", errbuf); goto cleanup; } if (xargs.linkdn != NULL) { /* * link information can be changed using modprinc. * However, link information can be changed only on the * standalone kerberos principal objects. A standalone * kerberos principal object is of type krbprincipal * structural objectclass. * * NOTE: kerberos principals on an ldap object can't be * linked to other ldap objects. */ if (optype == MODIFY_PRINCIPAL && kerberos_principal_object_type != KDB_STANDALONE_PRINCIPAL_OBJECT) { st = EINVAL; snprintf(errbuf, sizeof(errbuf), _("link information can not be set/updated as the " "kerberos principal belongs to an ldap object")); krb5_set_error_message(context, st, "%s", errbuf); goto cleanup; } /* * Check the link information. If there is already a link * existing then this operation is not allowed. */ { char **linkdns=NULL; int j=0; if ((st=krb5_get_linkdn(context, entry, &linkdns)) != 0) { snprintf(errbuf, sizeof(errbuf), _("Failed getting object references")); krb5_set_error_message(context, st, "%s", errbuf); goto cleanup; } if (linkdns != NULL) { st = EINVAL; snprintf(errbuf, sizeof(errbuf), _("kerberos principal is already linked to a ldap " "object")); krb5_set_error_message(context, st, "%s", errbuf); for (j=0; linkdns[j] != NULL; ++j) free (linkdns[j]); free (linkdns); goto cleanup; } } establish_links = TRUE; } if (entry->mask & KADM5_LAST_SUCCESS) { memset(strval, 0, sizeof(strval)); if ((strval[0]=getstringtime(entry->last_success)) == NULL) goto cleanup; if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbLastSuccessfulAuth", LDAP_MOD_REPLACE, strval)) != 0) { free (strval[0]); goto cleanup; } free (strval[0]); } if (entry->mask & KADM5_LAST_FAILED) { memset(strval, 0, sizeof(strval)); if ((strval[0]=getstringtime(entry->last_failed)) == NULL) goto cleanup; if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbLastFailedAuth", LDAP_MOD_REPLACE, strval)) != 0) { free (strval[0]); goto cleanup; } free(strval[0]); } if (entry->mask & KADM5_FAIL_AUTH_COUNT) { krb5_kvno fail_auth_count; fail_auth_count = entry->fail_auth_count; if (entry->mask & KADM5_FAIL_AUTH_COUNT_INCREMENT) fail_auth_count++; st = krb5_add_int_mem_ldap_mod(&mods, "krbLoginFailedCount", LDAP_MOD_REPLACE, fail_auth_count); if (st != 0) goto cleanup; } else if (entry->mask & KADM5_FAIL_AUTH_COUNT_INCREMENT) { int attr_mask = 0; krb5_boolean has_fail_count; /* Check if the krbLoginFailedCount attribute exists. (Through * krb5 1.8.1, it wasn't set in new entries.) */ st = krb5_get_attributes_mask(context, entry, &attr_mask); if (st != 0) goto cleanup; has_fail_count = ((attr_mask & KDB_FAIL_AUTH_COUNT_ATTR) != 0); /* * If the client library and server supports RFC 4525, * then use it to increment by one the value of the * krbLoginFailedCount attribute. Otherwise, assert the * (provided) old value by deleting it before adding. */ #ifdef LDAP_MOD_INCREMENT if (ldap_server_handle->server_info->modify_increment && has_fail_count) { st = krb5_add_int_mem_ldap_mod(&mods, "krbLoginFailedCount", LDAP_MOD_INCREMENT, 1); if (st != 0) goto cleanup; } else { #endif /* LDAP_MOD_INCREMENT */ if (has_fail_count) { st = krb5_add_int_mem_ldap_mod(&mods, "krbLoginFailedCount", LDAP_MOD_DELETE, entry->fail_auth_count); if (st != 0) goto cleanup; } st = krb5_add_int_mem_ldap_mod(&mods, "krbLoginFailedCount", LDAP_MOD_ADD, entry->fail_auth_count + 1); if (st != 0) goto cleanup; #ifdef LDAP_MOD_INCREMENT } #endif } else if (optype == ADD_PRINCIPAL) { /* Initialize krbLoginFailedCount in new entries to help avoid a * race during the first failed login. */ st = krb5_add_int_mem_ldap_mod(&mods, "krbLoginFailedCount", LDAP_MOD_ADD, 0); } if (entry->mask & KADM5_MAX_LIFE) { if ((st=krb5_add_int_mem_ldap_mod(&mods, "krbmaxticketlife", LDAP_MOD_REPLACE, entry->max_life)) != 0) goto cleanup; } if (entry->mask & KADM5_MAX_RLIFE) { if ((st=krb5_add_int_mem_ldap_mod(&mods, "krbmaxrenewableage", LDAP_MOD_REPLACE, entry->max_renewable_life)) != 0) goto cleanup; } if (entry->mask & KADM5_ATTRIBUTES) { if ((st=krb5_add_int_mem_ldap_mod(&mods, "krbticketflags", LDAP_MOD_REPLACE, entry->attributes)) != 0) goto cleanup; } if (entry->mask & KADM5_PRINCIPAL) { memset(strval, 0, sizeof(strval)); strval[0] = user; if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbprincipalname", LDAP_MOD_REPLACE, strval)) != 0) goto cleanup; } if (entry->mask & KADM5_PRINC_EXPIRE_TIME) { memset(strval, 0, sizeof(strval)); if ((strval[0]=getstringtime(entry->expiration)) == NULL) goto cleanup; if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbprincipalexpiration", LDAP_MOD_REPLACE, strval)) != 0) { free (strval[0]); goto cleanup; } free (strval[0]); } if (entry->mask & KADM5_PW_EXPIRATION) { memset(strval, 0, sizeof(strval)); if ((strval[0]=getstringtime(entry->pw_expiration)) == NULL) goto cleanup; if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbpasswordexpiration", LDAP_MOD_REPLACE, strval)) != 0) { free (strval[0]); goto cleanup; } free (strval[0]); } if (entry->mask & KADM5_POLICY) { memset(&princ_ent, 0, sizeof(princ_ent)); for (tl_data=entry->tl_data; tl_data; tl_data=tl_data->tl_data_next) { if (tl_data->tl_data_type == KRB5_TL_KADM_DATA) { /* FIX ME: I guess the princ_ent should be freed after this call */ if ((st = krb5_lookup_tl_kadm_data(tl_data, &princ_ent)) != 0) { goto cleanup; } } } if (princ_ent.aux_attributes & KADM5_POLICY) { memset(strval, 0, sizeof(strval)); if ((st = krb5_ldap_name_to_policydn (context, princ_ent.policy, &polname)) != 0) goto cleanup; strval[0] = polname; if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbpwdpolicyreference", LDAP_MOD_REPLACE, strval)) != 0) goto cleanup; } else { st = EINVAL; krb5_set_error_message(context, st, "Password policy value null"); goto cleanup; } } else if (entry->mask & KADM5_LOAD && found_entry == TRUE) { /* * a load is special in that existing entries must have attrs that * removed. */ if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbpwdpolicyreference", LDAP_MOD_REPLACE, NULL)) != 0) goto cleanup; } if (entry->mask & KADM5_POLICY_CLR) { if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbpwdpolicyreference", LDAP_MOD_DELETE, NULL)) != 0) goto cleanup; } if (entry->mask & KADM5_KEY_DATA || entry->mask & KADM5_KVNO) { krb5_kvno mkvno; if ((st=krb5_dbe_lookup_mkvno(context, entry, &mkvno)) != 0) goto cleanup; bersecretkey = krb5_encode_krbsecretkey (entry->key_data, entry->n_key_data, mkvno); if ((st=krb5_add_ber_mem_ldap_mod(&mods, "krbprincipalkey", LDAP_MOD_REPLACE | LDAP_MOD_BVALUES, bersecretkey)) != 0) goto cleanup; if (!(entry->mask & KADM5_PRINCIPAL)) { memset(strval, 0, sizeof(strval)); if ((strval[0]=getstringtime(entry->pw_expiration)) == NULL) goto cleanup; if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbpasswordexpiration", LDAP_MOD_REPLACE, strval)) != 0) { free (strval[0]); goto cleanup; } free (strval[0]); } /* Update last password change whenever a new key is set */ { krb5_timestamp last_pw_changed; if ((st=krb5_dbe_lookup_last_pwd_change(context, entry, &last_pw_changed)) != 0) goto cleanup; memset(strval, 0, sizeof(strval)); if ((strval[0] = getstringtime(last_pw_changed)) == NULL) goto cleanup; if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbLastPwdChange", LDAP_MOD_REPLACE, strval)) != 0) { free (strval[0]); goto cleanup; } free (strval[0]); } } /* Modify Key data ends here */ /* Set tl_data */ if (entry->tl_data != NULL) { int count = 0; struct berval **ber_tl_data = NULL; krb5_tl_data *ptr; krb5_timestamp unlock_time; for (ptr = entry->tl_data; ptr != NULL; ptr = ptr->tl_data_next) { if (ptr->tl_data_type == KRB5_TL_LAST_PWD_CHANGE #ifdef SECURID || ptr->tl_data_type == KRB5_TL_DB_ARGS #endif || ptr->tl_data_type == KRB5_TL_KADM_DATA || ptr->tl_data_type == KDB_TL_USER_INFO || ptr->tl_data_type == KRB5_TL_CONSTRAINED_DELEGATION_ACL || ptr->tl_data_type == KRB5_TL_LAST_ADMIN_UNLOCK) continue; count++; } if (count != 0) { int j; ber_tl_data = (struct berval **) calloc (count + 1, sizeof (struct berval*)); if (ber_tl_data == NULL) { st = ENOMEM; goto cleanup; } for (j = 0, ptr = entry->tl_data; ptr != NULL; ptr = ptr->tl_data_next) { /* Ignore tl_data that are stored in separate directory * attributes */ if (ptr->tl_data_type == KRB5_TL_LAST_PWD_CHANGE #ifdef SECURID || ptr->tl_data_type == KRB5_TL_DB_ARGS #endif || ptr->tl_data_type == KRB5_TL_KADM_DATA || ptr->tl_data_type == KDB_TL_USER_INFO || ptr->tl_data_type == KRB5_TL_CONSTRAINED_DELEGATION_ACL || ptr->tl_data_type == KRB5_TL_LAST_ADMIN_UNLOCK) continue; if ((st = tl_data2berval (ptr, &ber_tl_data[j])) != 0) break; j++; } if (st == 0) { ber_tl_data[count] = NULL; st=krb5_add_ber_mem_ldap_mod(&mods, "krbExtraData", LDAP_MOD_REPLACE | LDAP_MOD_BVALUES, ber_tl_data); } for (j = 0; ber_tl_data[j] != NULL; j++) { free(ber_tl_data[j]->bv_val); free(ber_tl_data[j]); } free(ber_tl_data); if (st != 0) goto cleanup; } if ((st=krb5_dbe_lookup_last_admin_unlock(context, entry, &unlock_time)) != 0) goto cleanup; if (unlock_time != 0) { /* Update last admin unlock */ memset(strval, 0, sizeof(strval)); if ((strval[0] = getstringtime(unlock_time)) == NULL) goto cleanup; if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbLastAdminUnlock", LDAP_MOD_REPLACE, strval)) != 0) { free (strval[0]); goto cleanup; } free (strval[0]); } } /* Directory specific attribute */ if (xargs.tktpolicydn != NULL) { int tmask=0; if (strlen(xargs.tktpolicydn) != 0) { st = checkattributevalue(ld, xargs.tktpolicydn, "objectclass", policyclass, &tmask); CHECK_CLASS_VALIDITY(st, tmask, _("ticket policy object value: ")); strval[0] = xargs.tktpolicydn; strval[1] = NULL; if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbticketpolicyreference", LDAP_MOD_REPLACE, strval)) != 0) goto cleanup; } else { /* if xargs.tktpolicydn is a empty string, then delete * already existing krbticketpolicyreference attr */ if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbticketpolicyreference", LDAP_MOD_DELETE, NULL)) != 0) goto cleanup; } } if (establish_links == TRUE) { memset(strval, 0, sizeof(strval)); strval[0] = xargs.linkdn; if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbObjectReferences", LDAP_MOD_REPLACE, strval)) != 0) goto cleanup; } /* * in case mods is NULL then return * not sure but can happen in a modprinc * so no need to return an error * addprinc will at least have the principal name * and the keys passed in */ if (mods == NULL) goto cleanup; if (create_standalone_prinicipal == TRUE) { memset(strval, 0, sizeof(strval)); strval[0] = "krbprincipal"; strval[1] = "krbprincipalaux"; strval[2] = "krbTicketPolicyAux"; if ((st=krb5_add_str_mem_ldap_mod(&mods, "objectclass", LDAP_MOD_ADD, strval)) != 0) goto cleanup; st = ldap_add_ext_s(ld, standalone_principal_dn, mods, NULL, NULL); if (st == LDAP_ALREADY_EXISTS && entry->mask & KADM5_LOAD) { /* a load operation must replace an existing entry */ st = ldap_delete_ext_s(ld, standalone_principal_dn, NULL, NULL); if (st != LDAP_SUCCESS) { snprintf(errbuf, sizeof(errbuf), _("Principal delete failed (trying to replace " "entry): %s"), ldap_err2string(st)); st = translate_ldap_error (st, OP_ADD); krb5_set_error_message(context, st, "%s", errbuf); goto cleanup; } else { st = ldap_add_ext_s(ld, standalone_principal_dn, mods, NULL, NULL); } } if (st != LDAP_SUCCESS) { snprintf(errbuf, sizeof(errbuf), _("Principal add failed: %s"), ldap_err2string(st)); st = translate_ldap_error (st, OP_ADD); krb5_set_error_message(context, st, "%s", errbuf); goto cleanup; } } else { /* * Here existing ldap object is modified and can be related * to any attribute, so always ensure that the ldap * object is extended with all the kerberos related * objectclasses so that there are no constraint * violations. */ { char *attrvalues[] = {"krbprincipalaux", "krbTicketPolicyAux", NULL}; int p, q, r=0, amask=0; if ((st=checkattributevalue(ld, (xargs.dn) ? xargs.dn : principal_dn, "objectclass", attrvalues, &amask)) != 0) goto cleanup; memset(strval, 0, sizeof(strval)); for (p=1, q=0; p<=2; p<<=1, ++q) { if ((p & amask) == 0) strval[r++] = attrvalues[q]; } if (r != 0) { if ((st=krb5_add_str_mem_ldap_mod(&mods, "objectclass", LDAP_MOD_ADD, strval)) != 0) goto cleanup; } } if (xargs.dn != NULL) st=ldap_modify_ext_s(ld, xargs.dn, mods, NULL, NULL); else st = ldap_modify_ext_s(ld, principal_dn, mods, NULL, NULL); if (st != LDAP_SUCCESS) { snprintf(errbuf, sizeof(errbuf), _("User modification failed: %s"), ldap_err2string(st)); st = translate_ldap_error (st, OP_MOD); krb5_set_error_message(context, st, "%s", errbuf); goto cleanup; } if (entry->mask & KADM5_FAIL_AUTH_COUNT_INCREMENT) entry->fail_auth_count++; } cleanup: if (user) free(user); if (filtuser) free(filtuser); free_xargs(xargs); if (standalone_principal_dn) free(standalone_principal_dn); if (principal_dn) free (principal_dn); if (polname != NULL) free(polname); if (subtree) free (subtree); if (bersecretkey) { for (l=0; bersecretkey[l]; ++l) { if (bersecretkey[l]->bv_val) free (bersecretkey[l]->bv_val); free (bersecretkey[l]); } free (bersecretkey); } if (keys) free (keys); ldap_mods_free(mods, 1); krb5_ldap_put_handle_to_pool(ldap_context, ldap_server_handle); return(st); }
krb5_error_code krb5_ldap_list_realm(krb5_context context, char ***realms) { char **values = NULL; unsigned int i = 0; int count = 0; krb5_error_code st = 0, tempst = 0; LDAP *ld = NULL; LDAPMessage *result = NULL, *ent = NULL; kdb5_dal_handle *dal_handle = NULL; krb5_ldap_context *ldap_context = NULL; krb5_ldap_server_handle *ldap_server_handle = NULL; SETUP_CONTEXT (); /* get the kerberos container DN information */ if (ldap_context->krbcontainer == NULL) { if ((st = krb5_ldap_read_krbcontainer_params(context, &(ldap_context->krbcontainer))) != 0) goto cleanup; } /* get ldap handle */ GET_HANDLE (); { char *cn[] = {"cn", NULL}; LDAP_SEARCH(ldap_context->krbcontainer->DN, LDAP_SCOPE_ONELEVEL, "(objectclass=krbRealmContainer)", cn); } *realms = NULL; count = ldap_count_entries (ld, result); if (count == -1) { ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &st); st = set_ldap_error (context, st, OP_SEARCH); goto cleanup; } *realms = calloc((unsigned int) count+1, sizeof (char *)); CHECK_NULL(*realms); for (ent = ldap_first_entry(ld, result), count = 0; ent != NULL; ent = ldap_next_entry(ld, ent)) { if ((values = ldap_get_values (ld, ent, "cn")) != NULL) { (*realms)[count] = strdup(values[0]); CHECK_NULL((*realms)[count]); count += 1; ldap_value_free(values); } } /* for (ent= ... */ ldap_msgfree(result); cleanup: /* some error, free up all the memory */ if (st != 0) { if (*realms) { for (i=0; (*realms)[i] != NULL; ++i) { free ((*realms)[i]); } free (*realms); *realms = NULL; } } /* If there are no elements, still return a NULL terminated array */ krb5_ldap_put_handle_to_pool(ldap_context, ldap_server_handle); return st; }
/* * Class: sun_nio_ch_SctpChannelImpl * Method: initIDs * Signature: ()V */ JNIEXPORT void JNICALL Java_sun_nio_ch_SctpChannelImpl_initIDs (JNIEnv *env, jclass klass) { jclass cls; /* SctpMessageInfoImpl */ cls = (*env)->FindClass(env, MESSAGE_IMPL_CLASS); CHECK_NULL(cls); smi_class = (*env)->NewGlobalRef(env, cls); CHECK_NULL(smi_class); smi_ctrID = (*env)->GetMethodID(env, cls, "<init>", "(ILjava/net/SocketAddress;IIZZI)V"); CHECK_NULL(smi_ctrID); /* SctpResultContainer */ cls = (*env)->FindClass(env, RESULT_CONTAINER_CLASS); CHECK_NULL(cls); src_valueID = (*env)->GetFieldID(env, cls, "value", "Ljava/lang/Object;"); CHECK_NULL(src_valueID); src_typeID = (*env)->GetFieldID(env, cls, "type", "I"); CHECK_NULL(src_typeID); /* SctpSendFailed */ cls = (*env)->FindClass(env, SEND_FAILED_CLASS); CHECK_NULL(cls); ssf_class = (*env)->NewGlobalRef(env, cls); CHECK_NULL(ssf_class); ssf_ctrID = (*env)->GetMethodID(env, cls, "<init>", "(ILjava/net/SocketAddress;Ljava/nio/ByteBuffer;II)V"); CHECK_NULL(ssf_ctrID); /* SctpAssocChange */ cls = (*env)->FindClass(env, ASSOC_CHANGE_CLASS); CHECK_NULL(cls); sac_class = (*env)->NewGlobalRef(env, cls); CHECK_NULL(sac_class); sac_ctrID = (*env)->GetMethodID(env, cls, "<init>", "(IIII)V"); CHECK_NULL(sac_ctrID); /* SctpPeerAddrChange */ cls = (*env)->FindClass(env, PEER_CHANGE_CLASS); CHECK_NULL(cls); spc_class = (*env)->NewGlobalRef(env, cls); CHECK_NULL(spc_class); spc_ctrID = (*env)->GetMethodID(env, cls, "<init>", "(ILjava/net/SocketAddress;I)V"); CHECK_NULL(spc_ctrID); /* sun.nio.ch.SctpShutdown */ cls = (*env)->FindClass(env, SHUTDOWN_CLASS); CHECK_NULL(cls); ss_class = (*env)->NewGlobalRef(env, cls); CHECK_NULL(ss_class); ss_ctrID = (*env)->GetMethodID(env, cls, "<init>", "(I)V"); CHECK_NULL(ss_ctrID); /* InetSocketAddress */ cls = (*env)->FindClass(env, "java/net/InetSocketAddress"); CHECK_NULL(cls); isa_addrID = (*env)->GetFieldID(env, cls, "addr", "Ljava/net/InetAddress;"); CHECK_NULL(isa_addrID); isa_portID = (*env)->GetFieldID(env, cls, "port", "I"); }
krb5_error_code krb5_ldap_create_realm(krb5_context context, krb5_ldap_realm_params *rparams, int mask) { LDAP *ld=NULL; krb5_error_code st=0; char *dn=NULL; char *strval[4]={NULL}; char *contref[2]={NULL}; LDAPMod **mods = NULL; int i=0, objectmask=0, subtreecount=0; kdb5_dal_handle *dal_handle=NULL; krb5_ldap_context *ldap_context=NULL; krb5_ldap_server_handle *ldap_server_handle=NULL; char *realm_name; SETUP_CONTEXT (); /* Check input validity ... */ if (ldap_context->krbcontainer == NULL || ldap_context->krbcontainer->DN == NULL || rparams == NULL || rparams->realm_name == NULL || ((mask & LDAP_REALM_SUBTREE) && rparams->subtree == NULL) || ((mask & LDAP_REALM_CONTREF) && rparams->containerref == NULL) || ((mask & LDAP_REALM_POLICYREFERENCE) && rparams->policyreference == NULL) || 0) { st = EINVAL; return st; } if (ldap_context->krbcontainer == NULL) { if ((st = krb5_ldap_read_krbcontainer_params(context, &(ldap_context->krbcontainer))) != 0) goto cleanup; } /* get ldap handle */ GET_HANDLE (); realm_name = rparams->realm_name; if (asprintf(&dn, "cn=%s,%s", realm_name, ldap_context->krbcontainer->DN) < 0) dn = NULL; CHECK_NULL(dn); strval[0] = realm_name; strval[1] = NULL; if ((st=krb5_add_str_mem_ldap_mod(&mods, "cn", LDAP_MOD_ADD, strval)) != 0) goto cleanup; strval[0] = "top"; strval[1] = "krbrealmcontainer"; strval[2] = "krbticketpolicyaux"; strval[3] = NULL; if ((st=krb5_add_str_mem_ldap_mod(&mods, "objectclass", LDAP_MOD_ADD, strval)) != 0) goto cleanup; /* SUBTREE ATTRIBUTE */ if (mask & LDAP_REALM_SUBTREE) { if ( rparams->subtree!=NULL) { subtreecount = rparams->subtreecount; for (i=0; rparams->subtree[i]!=NULL && i<subtreecount; i++) { if (strlen(rparams->subtree[i]) != 0) { st = checkattributevalue(ld, rparams->subtree[i], "Objectclass", subtreeclass, &objectmask); CHECK_CLASS_VALIDITY(st, objectmask, _("realm object value: ")); } } if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbsubtrees", LDAP_MOD_ADD, rparams->subtree)) != 0) { goto cleanup; } } } /* CONTAINER REFERENCE ATTRIBUTE */ if (mask & LDAP_REALM_CONTREF) { if (strlen(rparams->containerref) != 0 ) { st = checkattributevalue(ld, rparams->containerref, "Objectclass", subtreeclass, &objectmask); CHECK_CLASS_VALIDITY(st, objectmask, "realm object value: "); contref[0] = rparams->containerref; contref[1] = NULL; if ((st=krb5_add_str_mem_ldap_mod(&mods, "krbPrincContainerRef", LDAP_MOD_ADD, contref)) != 0) goto cleanup; } } /* SEARCHSCOPE ATTRIBUTE */ if (mask & LDAP_REALM_SEARCHSCOPE) { if ((st=krb5_add_int_mem_ldap_mod(&mods, "krbsearchscope", LDAP_MOD_ADD, (rparams->search_scope == LDAP_SCOPE_ONELEVEL || rparams->search_scope == LDAP_SCOPE_SUBTREE) ? rparams->search_scope : LDAP_SCOPE_SUBTREE)) != 0) goto cleanup; } if (mask & LDAP_REALM_MAXRENEWLIFE) { if ((st=krb5_add_int_mem_ldap_mod(&mods, "krbMaxRenewableAge", LDAP_MOD_ADD, rparams->max_renewable_life)) != 0) goto cleanup; } /* krbMaxTicketLife ATTRIBUTE */ if (mask & LDAP_REALM_MAXTICKETLIFE) { if ((st=krb5_add_int_mem_ldap_mod(&mods, "krbMaxTicketLife", LDAP_MOD_ADD, rparams->max_life)) != 0) goto cleanup; } /* krbTicketFlags ATTRIBUTE */ if (mask & LDAP_REALM_KRBTICKETFLAGS) { if ((st=krb5_add_int_mem_ldap_mod(&mods, "krbTicketFlags", LDAP_MOD_ADD, rparams->tktflags)) != 0) goto cleanup; } /* realm creation operation */ if ((st=ldap_add_ext_s(ld, dn, mods, NULL, NULL)) != LDAP_SUCCESS) { st = set_ldap_error (context, st, OP_ADD); goto cleanup; } cleanup: if (dn) free(dn); ldap_mods_free(mods, 1); krb5_ldap_put_handle_to_pool(ldap_context, ldap_server_handle); return st; }
static int l_receive (GPPort *p, GPFsErr *context, unsigned char **rb, unsigned int *rbs, unsigned int timeout) { unsigned char c, d; int error_flag; unsigned int i, j, rbs_internal; unsigned char checksum; int result; CHECK_NULL (p && rb && rbs); for (i = 0; ; ) { CHECK (gp_port_set_timeout (p, timeout)); CHECK (gp_port_read (p, &c, 1)); CHECK (gp_port_set_timeout (p, DEFAULT_TIMEOUT)); switch (c) { case ENQ: /* ENQ received. We can proceed. */ break; case ACK: /* ACK received. We'll try again at most ten times. */ if (i == 9) { /* * The camera hangs! Although it could be * that the camera accepts one of the * commands * - KONICA_CANCEL, * - KONICA_GET_IO_CAPABILITY, and * - KONICA_SET_IO_CAPABILITY, * we can not get the camera back to working * correctly. */ return (-1); } i++; break; default: /* * We'll dump this data until we get ENQ (then, we'll * proceed) or nothing any more (then, we'll report * error). */ for (;;) { CHECK (gp_port_read (p, &c, 1)); if (c == ENQ) break; } break; } if (c == ENQ) break; } /* Write ACK. */ CHECK (gp_port_write (p, "\6", 1)); for (*rbs = 0; ; ) { for (j = 0; ; j++) { CHECK (gp_port_read (p, &c, 1)); switch (c) { case STX: /* STX received. We can proceed. */ break; default: /* We'll dump this data and try again. */ continue; } /* * Read 2 bytes for size (low order byte, high order * byte) plus ESC quotes. */ CHECK (l_esc_read (p, &c)); checksum = c; CHECK (l_esc_read (p, &d)); checksum += d; rbs_internal = (d << 8) | c; if (*rbs == 0) *rb = malloc (rbs_internal * sizeof (char)); else *rb = realloc (*rb, sizeof (char) * (*rbs + rbs_internal)); /* Read 'rbs_internal' bytes data plus ESC quotes. */ error_flag = 0; { unsigned int read = 0, r = 0; while (read < rbs_internal) { /* * Read the specified amount of bytes. We will probably read more * because some bytes will be quoted. */ GP_DEBUG ("Reading %i bytes (%i of %i already read)...", rbs_internal - read, read, rbs_internal); result = gp_port_read (p, &((*rb)[*rbs + read]), rbs_internal - read); if (result < 0) { error_flag = 1; break; } r = rbs_internal - read; /* Unescape the data we just read */ for (i = read; i < read + r; i++) { unsigned char *c = &(*rb)[*rbs + i]; /* The HP PhotoSmart does not escape every special code, only * some and it gets confused if we do this checks. By relaxing * these, it now downloads images etc. */ #ifndef LESSER_ESCAPES if ((*c == STX) || (*c == ETX) || (*c == ENQ ) || (*c == ACK) || (*c == XOFF) || (*c == XON) || (*c == NACK) || (*c == ETB)) { #else /* LESSER_ESCAPES */ if ((*c == STX) || (*c == XOFF) || (*c == XON)) { #endif /* LESSER_ESCAPES */ GP_DEBUG ("Wrong ESC masking!"); error_flag = 1; break; } else if (*c == ESC) { if (i == read + r - 1) { CHECK (gp_port_read (p, &((*rb)[*rbs + read + r]), 1)); r++; } *c = (~*(c + 1) & 0xff); if ((*c != STX ) && (*c != ETX ) && (*c != ENQ) && (*c != ACK ) && (*c != XOFF) && (*c != XON) && (*c != NACK) && (*c != ETB ) && (*c != ESC)) { GP_DEBUG ("Wrong ESC masking!"); error_flag = 1; break; } memmove (c + 1, c + 2, read + r - i - 2); r--; } checksum += (*rb)[*rbs + i]; } if (error_flag) break; read += r; } } if (!error_flag) { CHECK (gp_port_read (p, &d, 1)); switch (d) { case ETX: /* * ETX received. This is the last * packet. */ GP_DEBUG ("Last packet."); break; case ETB: /* * ETB received. There are more * packets to come. */ GP_DEBUG ("More packets coming."); break; default: /* * We get more bytes than expected. * Nothing serious, as we will simply * dump all bytes until we receive * ETX or ETB. Later, we'll read the * checksum with ESC quotes and * reject the packet. */ while ((d != ETX) && (d != ETB)) { CHECK (gp_port_read (p, &d, 1)); } error_flag = 1; break; } } checksum += d; /* Read 1 byte for checksum plus ESC quotes. */ CHECK (l_esc_read (p, &c)); if ((c == checksum) && (!error_flag)) { *rbs += rbs_internal; /* Write ACK. */ CHECK (gp_port_write (p, "\6", 1)); break; } else { /* * Checksum wrong or transmission error. The * camera will send us the data at the most * three times. */ GP_DEBUG ("Checksum wrong: expected %i, " "got %i.", c, checksum); if (j == 2) return (-1); /* Write NACK. */ c = NACK; CHECK (gp_port_write (p, &c, 1)); continue; } } CHECK (gp_port_read (p, &c, 1)); switch (c) { case EOT: /* EOT received. We can proceed. */ break; default: /* Should not happen. */ return (-1); } /* * Depending on d, we will either continue to receive data or * stop. * * - ETX: We are all done. * - ETB: We expect more data. * - else: Should not happen. */ switch (d) { case ETX: /* We are all done. */ return (0); case ETB: /* We expect more data. Read ENQ. */ CHECK (gp_port_read (p, &c, 1)); switch (c) { case ENQ: /* ENQ received. We can proceed. */ break; default: /* Should not happen. */ return (-1); } #if 0 if (_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) { GP_DEBUG ("Trying to cancel operation..."); CHECK (k_cancel (p, context, &command)); GP_DEBUG ("Operation 0x%x cancelled.", command); return (-1); } #endif /* Write ACK. */ CHECK (gp_port_write (p, "\6", 1)); break; default: /* Should not happen. */ return (-1); } } } int l_send_receive ( GPPort *p, GPFsErr *c, unsigned char *send_buffer, unsigned int send_buffer_size, unsigned char **receive_buffer, unsigned int *receive_buffer_size, unsigned int timeout, unsigned char **image_buffer, unsigned int *image_buffer_size) { if (!timeout) timeout = DEFAULT_TIMEOUT; /* Send data. */ CHECK (l_send (p, c, send_buffer, send_buffer_size)); /* Receive data. */ if (image_buffer_size) *receive_buffer_size = *image_buffer_size; CHECK (l_receive (p, c, receive_buffer, receive_buffer_size, timeout)); /* Check if we've received the control data. */ if ((*receive_buffer_size > 1) && (((*receive_buffer)[0] == send_buffer[0]) && ((*receive_buffer)[1] == send_buffer[1]))) return (0); /* We didn't receive control data yet. */ *image_buffer = *receive_buffer; *image_buffer_size = *receive_buffer_size; *receive_buffer = NULL; /* Receive control data. */ CHECK (l_receive (p, c, receive_buffer, receive_buffer_size, DEFAULT_TIMEOUT)); /* Sanity check: Did we receive the right control data? */ if (((*receive_buffer)[0] != send_buffer[0]) || ((*receive_buffer)[1] != send_buffer[1])) return (-1); return (0); }
krb5_error_code krb5_ldap_read_realm_params(krb5_context context, char *lrealm, krb5_ldap_realm_params **rlparamp, int *mask) { char **values=NULL, *krbcontDN=NULL /*, *curr=NULL */; krb5_error_code st=0, tempst=0; LDAP *ld=NULL; LDAPMessage *result=NULL,*ent=NULL; krb5_ldap_realm_params *rlparams=NULL; kdb5_dal_handle *dal_handle=NULL; krb5_ldap_context *ldap_context=NULL; krb5_ldap_server_handle *ldap_server_handle=NULL; int x=0; SETUP_CONTEXT (); /* validate the input parameter */ if (lrealm == NULL || ldap_context->krbcontainer == NULL || ldap_context->krbcontainer->DN == NULL) { st = EINVAL; goto cleanup; } /* read kerberos container, if not read already */ if (ldap_context->krbcontainer == NULL) { if ((st = krb5_ldap_read_krbcontainer_params(context, &(ldap_context->krbcontainer))) != 0) goto cleanup; } /* get ldap handle */ GET_HANDLE (); /* Initialize realm container structure */ rlparams =(krb5_ldap_realm_params *) malloc(sizeof(krb5_ldap_realm_params)); CHECK_NULL(rlparams); memset(rlparams, 0, sizeof(krb5_ldap_realm_params)); /* allocate tl_data structure to store MASK information */ rlparams->tl_data = malloc (sizeof(krb5_tl_data)); if (rlparams->tl_data == NULL) { st = ENOMEM; goto cleanup; } memset(rlparams->tl_data, 0, sizeof(krb5_tl_data)); rlparams->tl_data->tl_data_type = KDB_TL_USER_INFO; /* set the mask parameter to 0 */ *mask = 0; /* set default values */ rlparams->search_scope = LDAP_SCOPE_SUBTREE; krbcontDN = ldap_context->krbcontainer->DN; if (asprintf(&rlparams->realmdn, "cn=%s,%s", lrealm, krbcontDN) < 0) { rlparams->realmdn = NULL; st = ENOMEM; goto cleanup; } /* populate the realm name in the structure */ rlparams->realm_name = strdup(lrealm); CHECK_NULL(rlparams->realm_name); LDAP_SEARCH(rlparams->realmdn, LDAP_SCOPE_BASE, "(objectclass=krbRealmContainer)", realm_attributes); if ((st = ldap_count_entries(ld, result)) <= 0) { /* This could happen when the DN used to bind and read the realm object * does not have sufficient rights to read its attributes */ st = KRB5_KDB_ACCESS_ERROR; /* return some other error ? */ goto cleanup; } ent = ldap_first_entry (ld, result); if (ent == NULL) { ldap_get_option (ld, LDAP_OPT_ERROR_NUMBER, (void *) &st); #if 0 st = translate_ldap_error(st, OP_SEARCH); #endif goto cleanup; } /* Read the attributes */ { if ((values=ldap_get_values(ld, ent, "krbSubTrees")) != NULL) { rlparams->subtreecount = ldap_count_values(values); rlparams->subtree = (char **) malloc(sizeof(char *) * (rlparams->subtreecount + 1)); if (rlparams->subtree == NULL) { st = ENOMEM; goto cleanup; } for (x=0; x<rlparams->subtreecount; x++) { rlparams->subtree[x] = strdup(values[x]); if (rlparams->subtree[x] == NULL) { st = ENOMEM; goto cleanup; } } rlparams->subtree[rlparams->subtreecount] = NULL; *mask |= LDAP_REALM_SUBTREE; ldap_value_free(values); } if((values=ldap_get_values(ld, ent, "krbPrincContainerRef")) != NULL) { rlparams->containerref = strdup(values[0]); if(rlparams->containerref == NULL) { st = ENOMEM; goto cleanup; } *mask |= LDAP_REALM_CONTREF; ldap_value_free(values); } if ((values=ldap_get_values(ld, ent, "krbSearchScope")) != NULL) { rlparams->search_scope=atoi(values[0]); /* searchscope can be ONE-LEVEL or SUBTREE, else default to SUBTREE */ if (!(rlparams->search_scope==1 || rlparams->search_scope==2)) rlparams->search_scope = LDAP_SCOPE_SUBTREE; *mask |= LDAP_REALM_SEARCHSCOPE; ldap_value_free(values); } if ((values=ldap_get_values(ld, ent, "krbMaxTicketLife")) != NULL) { rlparams->max_life = atoi(values[0]); *mask |= LDAP_REALM_MAXTICKETLIFE; ldap_value_free(values); } if ((values=ldap_get_values(ld, ent, "krbMaxRenewableAge")) != NULL) { rlparams->max_renewable_life = atoi(values[0]); *mask |= LDAP_REALM_MAXRENEWLIFE; ldap_value_free(values); } if ((values=ldap_get_values(ld, ent, "krbTicketFlags")) != NULL) { rlparams->tktflags = atoi(values[0]); *mask |= LDAP_REALM_KRBTICKETFLAGS; ldap_value_free(values); } } ldap_msgfree(result); /* * If all of maxtktlife, maxrenewlife and ticketflags are not directly * available, use the policy dn from the policy reference attribute, if * available, to fetch the missing. */ if ((!(*mask & LDAP_REALM_MAXTICKETLIFE && *mask & LDAP_REALM_MAXRENEWLIFE && *mask & LDAP_REALM_KRBTICKETFLAGS)) && rlparams->policyreference) { LDAP_SEARCH_1(rlparams->policyreference, LDAP_SCOPE_BASE, NULL, policy_attributes, IGNORE_STATUS); if (st != LDAP_SUCCESS && st != LDAP_NO_SUCH_OBJECT) { int ost = st; st = translate_ldap_error (st, OP_SEARCH); krb5_set_error_message(context, st, _("Policy object read failed: %s"), ldap_err2string(ost)); goto cleanup; } ent = ldap_first_entry (ld, result); if (ent != NULL) { if ((*mask & LDAP_REALM_MAXTICKETLIFE) == 0) { if ((values=ldap_get_values(ld, ent, "krbmaxticketlife")) != NULL) { rlparams->max_life = atoi(values[0]); *mask |= LDAP_REALM_MAXTICKETLIFE; ldap_value_free(values); } } if ((*mask & LDAP_REALM_MAXRENEWLIFE) == 0) { if ((values=ldap_get_values(ld, ent, "krbmaxrenewableage")) != NULL) { rlparams->max_renewable_life = atoi(values[0]); *mask |= LDAP_REALM_MAXRENEWLIFE; ldap_value_free(values); } } if ((*mask & LDAP_REALM_KRBTICKETFLAGS) == 0) { if ((values=ldap_get_values(ld, ent, "krbticketflags")) != NULL) { rlparams->tktflags = atoi(values[0]); *mask |= LDAP_REALM_KRBTICKETFLAGS; ldap_value_free(values); } } } ldap_msgfree(result); } rlparams->mask = *mask; *rlparamp = rlparams; st = store_tl_data(rlparams->tl_data, KDB_TL_MASK, mask); cleanup: /* if there is an error, free allocated structures */ if (st != 0) { krb5_ldap_free_realm_params(rlparams); *rlparamp=NULL; } krb5_ldap_put_handle_to_pool(ldap_context, ldap_server_handle); return st; }
/* SPI initialization and configuration */ int lgw_spi_open(void **spi_target_ptr) { int *spi_device = NULL; int dev; int a=0, b=0; int i; /* check input variables */ CHECK_NULL(spi_target_ptr); /* cannot be null, must point on a void pointer (*spi_target_ptr can be null) */ /* allocate memory for the device descriptor */ spi_device = malloc(sizeof(int)); if (spi_device == NULL) { DEBUG_MSG("ERROR: MALLOC FAIL\n"); return LGW_SPI_ERROR; } /* open SPI device */ dev = open(SPI_DEV_PATH, O_RDWR); if (dev < 0) { DEBUG_PRINTF("ERROR: failed to open SPI device %s\n", SPI_DEV_PATH); return LGW_SPI_ERROR; } /* setting SPI mode to 'mode 0' */ i = SPI_MODE_0; a = ioctl(dev, SPI_IOC_WR_MODE, &i); b = ioctl(dev, SPI_IOC_RD_MODE, &i); if ((a < 0) || (b < 0)) { DEBUG_MSG("ERROR: SPI PORT FAIL TO SET IN MODE 0\n"); close(dev); free(spi_device); return LGW_SPI_ERROR; } /* setting SPI max clk (in Hz) */ i = SPI_SPEED; a = ioctl(dev, SPI_IOC_WR_MAX_SPEED_HZ, &i); b = ioctl(dev, SPI_IOC_RD_MAX_SPEED_HZ, &i); if ((a < 0) || (b < 0)) { DEBUG_MSG("ERROR: SPI PORT FAIL TO SET MAX SPEED\n"); close(dev); free(spi_device); return LGW_SPI_ERROR; } /* setting SPI to MSB first */ i = 0; a = ioctl(dev, SPI_IOC_WR_LSB_FIRST, &i); b = ioctl(dev, SPI_IOC_RD_LSB_FIRST, &i); if ((a < 0) || (b < 0)) { DEBUG_MSG("ERROR: SPI PORT FAIL TO SET MSB FIRST\n"); close(dev); free(spi_device); return LGW_SPI_ERROR; } /* setting SPI to 8 bits per word */ i = 0; a = ioctl(dev, SPI_IOC_WR_BITS_PER_WORD, &i); b = ioctl(dev, SPI_IOC_RD_BITS_PER_WORD, &i); if ((a < 0) || (b < 0)) { DEBUG_MSG("ERROR: SPI PORT FAIL TO SET 8 BITS-PER-WORD\n"); close(dev); return LGW_SPI_ERROR; } *spi_device = dev; *spi_target_ptr = (void *)spi_device; DEBUG_MSG("Note: SPI port opened and configured ok\n"); return LGW_SPI_SUCCESS; }
/** * Transaction 5 - T5 * * Delete session * * Input: * SubscriberNumber * ServerId * ServerBit * DoRollback * Output: * ChangedBy * ChangedTime * Location * BranchExecuted */ int T5(void * obj, const SubscriberNumber inNumber, const SubscriberSuffix inSuffix, const ServerId inServerId, const ServerBit inServerBit, ChangedBy outChangedBy, ChangedTime outChangedTime, Location * outLocation, DoRollback inDoRollback, BranchExecuted * outBranchExecuted, BenchmarkTime * outTransactionTime){ Ndb * pNDB = (Ndb *) obj; NdbConnection * MyTransaction = 0; NdbOperation * MyOperation = 0; GroupId groupId; ActiveSessions sessions; Permission permission; BenchmarkTime start; get_time(&start); int check; NdbRecAttr * check2; MyTransaction = pNDB->startTransaction(); if (MyTransaction == NULL) error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0); MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE); CHECK_NULL(MyOperation, "T5-1: getNdbOperation", MyTransaction); check = MyOperation->readTupleExclusive(); CHECK_MINUS_ONE(check, "T5-1: readTuple", MyTransaction); check = MyOperation->equal(SUBSCRIBER_NUMBER, inNumber); CHECK_MINUS_ONE(check, "T5-1: equal subscriber", MyTransaction); check2 = MyOperation->getValue(SUBSCRIBER_LOCATION, (char *)outLocation); CHECK_NULL(check2, "T5-1: getValue location", MyTransaction); check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_BY, outChangedBy); CHECK_NULL(check2, "T5-1: getValue changed_by", MyTransaction); check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_TIME, outChangedTime); CHECK_NULL(check2, "T5-1: getValue changed_time", MyTransaction); check2 = MyOperation->getValue(SUBSCRIBER_GROUP, (char *)&groupId); CHECK_NULL(check2, "T5-1: getValue group", MyTransaction); check2 = MyOperation->getValue(SUBSCRIBER_SESSIONS, (char *)&sessions); CHECK_NULL(check2, "T5-1: getValue sessions", MyTransaction); check = MyTransaction->execute( NoCommit ); CHECK_MINUS_ONE(check, "T5-1: NoCommit", MyTransaction); /* Operation 2 */ MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE); CHECK_NULL(MyOperation, "T5-2: getNdbOperation", MyTransaction); check = MyOperation->readTuple(); CHECK_MINUS_ONE(check, "T5-2: readTuple", MyTransaction); check = MyOperation->equal(GROUP_ID, (char*)&groupId); CHECK_MINUS_ONE(check, "T5-2: equal group", MyTransaction); check2 = MyOperation->getValue(GROUP_ALLOW_DELETE, (char *)&permission); CHECK_NULL(check2, "T5-2: getValue allow_delete", MyTransaction); check = MyTransaction->execute( NoCommit ); CHECK_MINUS_ONE(check, "T5-2: NoCommit", MyTransaction); DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId); if(((permission & inServerBit) == inServerBit) && ((sessions & inServerBit) == inServerBit)){ DEBUG("deleting - "); /* Operation 3 */ MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE); CHECK_NULL(MyOperation, "T5-3: getNdbOperation", MyTransaction); check = MyOperation->deleteTuple(); CHECK_MINUS_ONE(check, "T5-3: deleteTuple", MyTransaction); check = MyOperation->equal(SESSION_SUBSCRIBER, (char*)inNumber); CHECK_MINUS_ONE(check, "T5-3: equal number", MyTransaction); check = MyOperation->equal(SESSION_SERVER, (char*)&inServerId); CHECK_MINUS_ONE(check, "T5-3: equal server id", MyTransaction); check = MyTransaction->execute( NoCommit ); CHECK_MINUS_ONE(check, "T5-3: NoCommit", MyTransaction); /* Operation 4 */ MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE); CHECK_NULL(MyOperation, "T5-4: getNdbOperation", MyTransaction); check = MyOperation->interpretedUpdateTuple(); CHECK_MINUS_ONE(check, "T5-4: interpretedUpdateTuple", MyTransaction); check = MyOperation->equal(SUBSCRIBER_NUMBER, (char*)inNumber); CHECK_MINUS_ONE(check, "T5-4: equal number", MyTransaction); check = MyOperation->subValue(SUBSCRIBER_SESSIONS, (uint32)inServerBit); CHECK_MINUS_ONE(check, "T5-4: dec value", MyTransaction); check = MyTransaction->execute( NoCommit ); CHECK_MINUS_ONE(check, "T5-4: NoCommit", MyTransaction); /* Operation 5 */ MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE); CHECK_NULL(MyOperation, "T5-5: getNdbOperation", MyTransaction); check = MyOperation->interpretedUpdateTuple(); CHECK_MINUS_ONE(check, "T5-5: interpretedUpdateTuple", MyTransaction); check = MyOperation->equal(SERVER_ID, (char*)&inServerId); CHECK_MINUS_ONE(check, "T5-5: equal serverId", MyTransaction); check = MyOperation->equal(SERVER_SUBSCRIBER_SUFFIX, (char*)inSuffix); CHECK_MINUS_ONE(check, "T5-5: equal suffix", MyTransaction); check = MyOperation->incValue(SERVER_DELETES, (uint32)1); CHECK_MINUS_ONE(check, "T5-5: inc value", MyTransaction); check = MyTransaction->execute( NoCommit ); CHECK_MINUS_ONE(check, "T5-5: NoCommit", MyTransaction); (* outBranchExecuted) = 1; } else { DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - ")); DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - ")); (* outBranchExecuted) = 0; } if(!inDoRollback){ DEBUG("commit\n"); check = MyTransaction->execute( Commit ); CHECK_MINUS_ONE(check, "T5: Commit", MyTransaction); } else { DEBUG("rollback\n"); check = MyTransaction->execute(Rollback); CHECK_MINUS_ONE(check, "T5:Rollback", MyTransaction); } pNDB->closeTransaction(MyTransaction); get_time(outTransactionTime); time_diff(outTransactionTime, &start); return 0; }
/* * Class: sun_net_ExtendedOptionsImpl * Method: init * Signature: ()V */ JNIEXPORT void JNICALL Java_sun_net_ExtendedOptionsImpl_init (JNIEnv *env, jclass UNUSED) { static int initialized = 0; jclass c; /* Global class references */ if (initialized) { return; } c = (*env)->FindClass(env, "jdk/net/SocketFlow$Status"); CHECK_NULL(c); sf_status_class = (*env)->NewGlobalRef(env, c); CHECK_NULL(sf_status_class); /* int "fd" field of java.io.FileDescriptor */ c = (*env)->FindClass(env, "java/io/FileDescriptor"); CHECK_NULL(c); sf_fd_fdID = (*env)->GetFieldID(env, c, "fd", "I"); CHECK_NULL(sf_fd_fdID); /* SocketFlow fields */ c = (*env)->FindClass(env, "jdk/net/SocketFlow"); /* status */ sf_status = (*env)->GetFieldID(env, c, "status", "Ljdk/net/SocketFlow$Status;"); CHECK_NULL(sf_status); /* priority */ sf_priority = (*env)->GetFieldID(env, c, "priority", "I"); CHECK_NULL(sf_priority); /* bandwidth */ sf_bandwidth = (*env)->GetFieldID(env, c, "bandwidth", "J"); CHECK_NULL(sf_bandwidth); /* Initialize the static enum values */ sfs_NOSTATUS = getEnumField(env, "NO_STATUS"); CHECK_NULL(sfs_NOSTATUS); sfs_OK = getEnumField(env, "OK"); CHECK_NULL(sfs_OK); sfs_NOPERMISSION = getEnumField(env, "NO_PERMISSION"); CHECK_NULL(sfs_NOPERMISSION); sfs_NOTCONNECTED = getEnumField(env, "NOT_CONNECTED"); CHECK_NULL(sfs_NOTCONNECTED); sfs_NOTSUPPORTED = getEnumField(env, "NOT_SUPPORTED"); CHECK_NULL(sfs_NOTSUPPORTED); sfs_ALREADYCREATED = getEnumField(env, "ALREADY_CREATED"); CHECK_NULL(sfs_ALREADYCREATED); sfs_INPROGRESS = getEnumField(env, "IN_PROGRESS"); CHECK_NULL(sfs_INPROGRESS); sfs_OTHER = getEnumField(env, "OTHER"); CHECK_NULL(sfs_OTHER); initialized = JNI_TRUE; }
PKIError CKMIssueRootCertificate (const uint8_t *uint8NotBefore, const uint8_t *uint8NotAfter, ByteArray *issuedRootCertificate) { FUNCTION_INIT(); UTF8String_t *rootName = NULL; UTCTime_t *notBefore = NULL; UTCTime_t *notAfter = NULL; BIT_STRING_t *subjectPublicKey = NULL; BIT_STRING_t *issuerPrivateKey = NULL; ByteArray pubKeyIss = BYTE_ARRAY_INITIALIZER; ByteArray privKeyIss = BYTE_ARRAY_INITIALIZER; ByteArray caName = BYTE_ARRAY_INITIALIZER; uint8_t caPublicKey[PUBLIC_KEY_SIZE]; uint8_t caPrivateKey[PRIVATE_KEY_SIZE]; uint8_t uint8caName[ISSUER_MAX_NAME_SIZE]; CHECK_NULL(issuedRootCertificate, ISSUER_NULL_PASSED); CHECK_NULL(issuedRootCertificate->data, ISSUER_NULL_PASSED); CHECK_LESS_EQUAL(ISSUER_MAX_CERT_SIZE, issuedRootCertificate->len, ISSUER_WRONG_BYTE_ARRAY_LEN); pubKeyIss.data = caPublicKey; pubKeyIss.len = PUBLIC_KEY_SIZE; privKeyIss.data = caPrivateKey; privKeyIss.len = PRIVATE_KEY_SIZE; caName.data = uint8caName; caName.len = ISSUER_MAX_NAME_SIZE; rootName = (UTF8String_t *)OICCalloc(1, sizeof(UTF8String_t)); CHECK_NULL(rootName, ISSUER_MEMORY_ALLOC_FAILED); notBefore = (UTCTime_t *)OICCalloc(1, sizeof(UTCTime_t)); CHECK_NULL(notBefore, ISSUER_MEMORY_ALLOC_FAILED); notAfter = (UTCTime_t *)OICCalloc(1, sizeof(UTCTime_t)); CHECK_NULL(notAfter, ISSUER_MEMORY_ALLOC_FAILED); subjectPublicKey = (BIT_STRING_t *)OICCalloc(1, sizeof(BIT_STRING_t)); CHECK_NULL(subjectPublicKey, ISSUER_MEMORY_ALLOC_FAILED); issuerPrivateKey = (BIT_STRING_t *)OICCalloc(1, sizeof(BIT_STRING_t)); CHECK_NULL(issuerPrivateKey, ISSUER_MEMORY_ALLOC_FAILED); //RootName CHECK_CALL(InitCKMInfo); CHECK_CALL(GetCAName, &caName); rootName->buf = caName.data; rootName->size = caName.len; //notBefore if (uint8NotBefore) { notBefore->buf = (uint8_t *)uint8NotBefore; } else { notBefore->buf = (uint8_t *)ISSUER_DEFAULT_NOT_BEFORE; } notBefore->size = strlen((const char *)notBefore->buf); //notAfter if (uint8NotAfter) { notAfter->buf = (uint8_t *)uint8NotAfter; } else { notAfter->buf = (uint8_t *)ISSUER_DEFAULT_NOT_AFTER; } notAfter->size = strlen((const char *)notAfter->buf); //common keys issuerPrivateKey->size = PRIVATE_KEY_SIZE + 1; //additional byte for ASN1_UNCOMPRESSED_KEY_ID issuerPrivateKey->buf = (uint8_t *)OICCalloc((issuerPrivateKey->size), sizeof(uint8_t)); CHECK_NULL(issuerPrivateKey->buf, ISSUER_MEMORY_ALLOC_FAILED); *(issuerPrivateKey->buf) = (uint8_t)ASN1_UNCOMPRESSED_KEY_ID; subjectPublicKey->size = PUBLIC_KEY_SIZE + 1; //additional byte for ASN1_UNCOMPRESSED_KEY_ID subjectPublicKey->buf = (uint8_t *)OICCalloc(subjectPublicKey->size, sizeof(uint8_t)); CHECK_NULL(subjectPublicKey->buf, ISSUER_MEMORY_ALLOC_FAILED); *(subjectPublicKey->buf) = (uint8_t)ASN1_UNCOMPRESSED_KEY_ID; //common keys //read CA key pair from the CA storage CHECK_CALL(InitCKMInfo); CHECK_CALL(GetCAPrivateKey, &privKeyIss); //additional byte for ASN1_UNCOMPRESSED_KEY_ID memcpy((issuerPrivateKey->buf) + 1, privKeyIss.data, PRIVATE_KEY_SIZE); CHECK_CALL(GetCAPublicKey, &pubKeyIss); //additional byte for ASN1_UNCOMPRESSED_KEY_ID memcpy((subjectPublicKey->buf) + 1, pubKeyIss.data, PUBLIC_KEY_SIZE); CHECK_CALL(GenerateCertificate, rootName, rootName, notBefore, notAfter, subjectPublicKey, issuerPrivateKey, issuedRootCertificate); CHECK_CALL(InitCKMInfo); CHECK_CALL(SetCACertificate, issuedRootCertificate); CHECK_CALL(SaveCKMInfo); FUNCTION_CLEAR( OICFree(rootName); OICFree(notBefore); OICFree(notAfter); ASN_STRUCT_FREE(asn_DEF_BIT_STRING, subjectPublicKey); ASN_STRUCT_FREE(asn_DEF_BIT_STRING, issuerPrivateKey); );
/** * Transaction 3 - T3 * * Read session details * * Input: * SubscriberNumber * ServerId * ServerBit * * Output: * BranchExecuted * SessionDetails * ChangedBy * ChangedTime * Location */ int T3(void * obj, const SubscriberNumber inNumber, const SubscriberSuffix inSuffix, const ServerId inServerId, const ServerBit inServerBit, SessionDetails outSessionDetails, ChangedBy outChangedBy, ChangedTime outChangedTime, Location * outLocation, BranchExecuted * outBranchExecuted, BenchmarkTime * outTransactionTime){ Ndb * pNDB = (Ndb *) obj; GroupId groupId; ActiveSessions sessions; Permission permission; BenchmarkTime start; get_time(&start); int check; NdbRecAttr * check2; NdbConnection * MyTransaction = pNDB->startTransaction(); if (MyTransaction == NULL) error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), 0); NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE); CHECK_NULL(MyOperation, "T3-1: getNdbOperation", MyTransaction); check = MyOperation->readTuple(); CHECK_MINUS_ONE(check, "T3-1: readTuple", MyTransaction); check = MyOperation->equal(IND_SUBSCRIBER_NUMBER, inNumber); CHECK_MINUS_ONE(check, "T3-1: equal subscriber", MyTransaction); check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION, (char *)outLocation); CHECK_NULL(check2, "T3-1: getValue location", MyTransaction); check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY, outChangedBy); CHECK_NULL(check2, "T3-1: getValue changed_by", MyTransaction); check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME, outChangedTime); CHECK_NULL(check2, "T3-1: getValue changed_time", MyTransaction); check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP, (char *)&groupId); CHECK_NULL(check2, "T3-1: getValue group", MyTransaction); check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS, (char *)&sessions); CHECK_NULL(check2, "T3-1: getValue sessions", MyTransaction); check = MyTransaction->execute( NoCommit ); CHECK_MINUS_ONE(check, "T3-1: NoCommit", MyTransaction); /* Operation 2 */ MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE); CHECK_NULL(MyOperation, "T3-2: getNdbOperation", MyTransaction); check = MyOperation->readTuple(); CHECK_MINUS_ONE(check, "T3-2: readTuple", MyTransaction); check = MyOperation->equal(IND_GROUP_ID, (char*)&groupId); CHECK_MINUS_ONE(check, "T3-2: equal group", MyTransaction); check2 = MyOperation->getValue(IND_GROUP_ALLOW_READ, (char *)&permission); CHECK_NULL(check2, "T3-2: getValue allow_read", MyTransaction); check = MyTransaction->execute( NoCommit ); CHECK_MINUS_ONE(check, "T3-2: NoCommit", MyTransaction); DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId); if(((permission & inServerBit) == inServerBit) && ((sessions & inServerBit) == inServerBit)){ DEBUG("reading - "); /* Operation 3 */ MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE); CHECK_NULL(MyOperation, "T3-3: getNdbOperation", MyTransaction); check = MyOperation->readTuple(); CHECK_MINUS_ONE(check, "T3-3: readTuple", MyTransaction); check = MyOperation->equal(IND_SESSION_SUBSCRIBER, (char*)inNumber); CHECK_MINUS_ONE(check, "T3-3: equal number", MyTransaction); check = MyOperation->equal(IND_SESSION_SERVER, (char*)&inServerId); CHECK_MINUS_ONE(check, "T3-3: equal server id", MyTransaction); check2 = MyOperation->getValue(IND_SESSION_DATA, (char *)outSessionDetails); CHECK_NULL(check2, "T3-3: getValue session details", MyTransaction); check = MyTransaction->execute( NoCommit ); CHECK_MINUS_ONE(check, "T3-3: NoCommit", MyTransaction); /* Operation 4 */ MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE); CHECK_NULL(MyOperation, "T3-4: getNdbOperation", MyTransaction); check = MyOperation->interpretedUpdateTuple(); CHECK_MINUS_ONE(check, "T3-4: interpretedUpdateTuple", MyTransaction); check = MyOperation->equal(IND_SERVER_ID, (char*)&inServerId); CHECK_MINUS_ONE(check, "T3-4: equal serverId", MyTransaction); check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX, (char*)inSuffix); CHECK_MINUS_ONE(check, "T3-4: equal suffix", MyTransaction); check = MyOperation->incValue(IND_SERVER_READS, (uint32)1); CHECK_MINUS_ONE(check, "T3-4: inc value", MyTransaction); check = MyTransaction->execute( NoCommit ); CHECK_MINUS_ONE(check, "T3-4: NoCommit", MyTransaction); (* outBranchExecuted) = 1; } else { (* outBranchExecuted) = 0; } DEBUG("commit\n"); check = MyTransaction->execute( Commit ); CHECK_MINUS_ONE(check, "T3: Commit", MyTransaction); pNDB->closeTransaction(MyTransaction); get_time(outTransactionTime); time_diff(outTransactionTime, &start); return 0; }
/** * Transaction 3 - T3 * * Read session details * * Input: * SubscriberNumber * ServerId * ServerBit * * Output: * BranchExecuted * SessionDetails * ChangedBy * ChangedTime * Location */ void userTransaction_T3(UserHandle * uh, SubscriberNumber inNumber, ServerId inServerId, ServerBit inServerBit, SessionDetails outSessionDetails, BranchExecuted * outBranchExecuted){ Ndb * pNDB = uh->pNDB; char outChangedBy [sizeof(ChangedBy) +(4-(sizeof(ChangedBy) & 3))]; char outChangedTime [sizeof(ChangedTime)+(4-(sizeof(ChangedTime) & 3))]; Location outLocation; GroupId groupId; ActiveSessions sessions; Permission permission; SubscriberSuffix inSuffix; DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId); int check; NdbRecAttr * check2; NdbConnection * MyTransaction = startTransaction(pNDB, inServerId, inNumber); if (MyTransaction == NULL) error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError()); NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE); CHECK_NULL(MyOperation, "T3-1: getNdbOperation", MyTransaction); MyOperation->readTuple(); MyOperation->equal(IND_SUBSCRIBER_NUMBER, inNumber); MyOperation->getValue(IND_SUBSCRIBER_LOCATION, (char *)&outLocation); MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY, outChangedBy); MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME, outChangedTime); MyOperation->getValue(IND_SUBSCRIBER_GROUP, (char *)&groupId); MyOperation->getValue(IND_SUBSCRIBER_SESSIONS, (char *)&sessions); check = MyTransaction->execute( NoCommit ); CHECK_MINUS_ONE(check, "T3-1: NoCommit", MyTransaction); /* Operation 2 */ MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE); CHECK_NULL(MyOperation, "T3-2: getNdbOperation", MyTransaction); MyOperation->readTuple(); MyOperation->equal(IND_GROUP_ID, (char*)&groupId); MyOperation->getValue(IND_GROUP_ALLOW_READ, (char *)&permission); check = MyTransaction->execute( NoCommit ); CHECK_MINUS_ONE(check, "T3-2: NoCommit", MyTransaction); if(((permission & inServerBit) == inServerBit) && ((sessions & inServerBit) == inServerBit)){ memcpy(inSuffix, &inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH); DEBUG2("reading(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix); /* Operation 3 */ MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE); CHECK_NULL(MyOperation, "T3-3: getNdbOperation", MyTransaction); MyOperation->simpleRead(); MyOperation->equal(IND_SESSION_SUBSCRIBER, (char*)inNumber); MyOperation->equal(IND_SESSION_SERVER, (char*)&inServerId); MyOperation->getValue(IND_SESSION_DATA, (char *)outSessionDetails); /* Operation 4 */ MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE); CHECK_NULL(MyOperation, "T3-4: getNdbOperation", MyTransaction); MyOperation->interpretedUpdateTuple(); MyOperation->equal(IND_SERVER_ID, (char*)&inServerId); MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX, (char*)inSuffix); MyOperation->incValue(IND_SERVER_READS, (uint32)1); (* outBranchExecuted) = 1; } else { (* outBranchExecuted) = 0; } DEBUG("commit..."); check = MyTransaction->execute( Commit ); CHECK_MINUS_ONE(check, "T3: Commit", MyTransaction); pNDB->closeTransaction(MyTransaction); DEBUG("done\n"); }