/* * initialize the index table: read it from language.idx or create * a new one and write it to the index file. A new index file is * created if the language set in config.pgp doesn't match the one * in language.idx or if the size of language.txt has changed. */ static void init_lang() { char indexfile[MAX_PATH]; char subtitles_file[MAX_PATH]; FILE *indexf; if (strcmp(language, "en") == 0) { subtitles_available = -1; return; /* use default messages */ } buildfilename (subtitles_file, langfile); if ((langf = fopen(subtitles_file, "rb")) == NULL) { subtitles_available = -1; return; } init_crc(); if ((strbuf = (char *) malloc(STRBUFSIZE)) == NULL) { fprintf(stderr, "Not enough memory for foreign subtitles\n"); fclose(langf); subtitles_available = -1; return; } buildfilename(indexfile, LANG_INDEXFILE); if ((indexf = fopen(indexfile, "rb")) != NULL) { if (fread(&indx_hdr, sizeof(indx_hdr), 1, indexf) == 1 && indx_hdr.lang_fsize == fsize(langf) && strcmp(indx_hdr.lang, language) == 0) { nmsg = indx_hdr.nmsg; indx_tbl = (struct indx_ent *) malloc(nmsg * sizeof(struct indx_ent)); if (indx_tbl == NULL) { fprintf(stderr, "Not enough memory for foreign subtitles\n"); fclose(indexf); fclose(langf); subtitles_available = -1; return; } if (fread(indx_tbl, sizeof(struct indx_ent), nmsg, indexf) != nmsg) { free(indx_tbl); /* create a new one */ indx_tbl = NULL; } } fclose(indexf); } if (indx_tbl == NULL && make_indexfile(indexfile) < 0) { fclose(langf); subtitles_available = -1; } else { subtitles_available = 1; } }
isc_result_t dst_key_getfilename(dns_name_t *name, dns_keytag_t id, unsigned int alg, int type, const char *directory, isc_mem_t *mctx, isc_buffer_t *buf) { isc_result_t result; REQUIRE(dst_initialized == ISC_TRUE); REQUIRE(dns_name_isabsolute(name)); REQUIRE((type & (DST_TYPE_PRIVATE | DST_TYPE_PUBLIC)) != 0); REQUIRE(mctx != NULL); REQUIRE(buf != NULL); CHECKALG(alg); result = buildfilename(name, id, alg, type, directory, buf); if (result == ISC_R_SUCCESS) { if (isc_buffer_availablelength(buf) > 0) isc_buffer_putuint8(buf, 0); else result = ISC_R_NOSPACE; } return (result); }
isc_result_t dst_key_buildfilename(const dst_key_t *key, int type, const char *directory, isc_buffer_t *out) { REQUIRE(VALID_KEY(key)); REQUIRE(type == DST_TYPE_PRIVATE || type == DST_TYPE_PUBLIC || type == 0); return (buildfilename(key->key_name, key->key_id, key->key_alg, type, directory, out)); }
char *buildsysfilename(char *result, char *fname) { #ifdef PGP_SYSTEM_DIR strcpy(result, PGP_SYSTEM_DIR); strcat(result, fname); if (file_exists(result)) return result; #endif buildfilename(result, fname); /* Put name back for error */ return result; }
isc_result_t dst_key_fromfile(dns_name_t *name, dns_keytag_t id, unsigned int alg, int type, const char *directory, isc_mem_t *mctx, dst_key_t **keyp) { char filename[ISC_DIR_NAMEMAX]; isc_buffer_t b; dst_key_t *key; isc_result_t result; REQUIRE(dst_initialized == ISC_TRUE); REQUIRE(dns_name_isabsolute(name)); REQUIRE((type & (DST_TYPE_PRIVATE | DST_TYPE_PUBLIC)) != 0); REQUIRE(mctx != NULL); REQUIRE(keyp != NULL && *keyp == NULL); CHECKALG(alg); isc_buffer_init(&b, filename, sizeof(filename)); result = buildfilename(name, id, alg, type, directory, &b); if (result != ISC_R_SUCCESS) return (result); key = NULL; result = dst_key_fromnamedfile(filename, type, mctx, &key); if (result != ISC_R_SUCCESS) return (result); result = computeid(key); if (result != ISC_R_SUCCESS) { dst_key_free(&key); return (result); } if (!dns_name_equal(name, key->key_name) || id != key->key_id || alg != key->key_alg) { dst_key_free(&key); return (DST_R_INVALIDPRIVATEKEY); } key->key_id = id; *keyp = key; return (ISC_R_SUCCESS); }
void printmessagefromtemplate(char *templatename) { printf("%s",putintemplate(buildfilename(templatename,""), 0,NULL,NULL)); }