diff --git a/Makefile b/Makefile index 90902ef..fcffebe 100644 --- a/Makefile +++ b/Makefile @@ -1,82 +1,84 @@ #!/usr/bin/make -f CFLAGS ?= -g -Wall PREFIX ?= /usr/local INSTALL ?= install #---------------- Do not modify below this point ------------------ INSTALL_DIR := $(INSTALL) -p -d -o root -g root -m 0755 INSTALL_FILE := $(INSTALL) -p -o root -g root -m 0644 INSTALL_PROGRAM := $(INSTALL) -p -o root -g root -m 0755 # -s INSTALL_SCRIPT := $(INSTALL) -p -o root -g root -m 0755 VERSION = $(shell cat VERSION) DOCS := AUTHORS ChangeLog CREDITS FILE-FORMAT FILE-FORMAT.html LICENSE TODO \ VERSION DISTFILES := $(DOCS) Makefile setup1.vdproj XGetopt.c XGetopt.h common.h \ debug.c define.h dumpblocks.c getidblock.c libpst.c libpst.h \ libstrfunc.c libstrfunc.h lspst.c lzfu.c lzfu.h moz-script \ readlog.vcproj readpst.1 readpst.c readpstlog.1 readpstlog.c \ testdebug.c timeconv.c timeconv.h w32pst.sln w32pst.vcproj PROGS := lspst readpst readpstlog pst2ldif nick2ldif ALL_PROGS := $(PROGS) dumpblocks getidblock testdebug all: $(PROGS) XGetopt.o: XGetopt.h debug.o: define.h dumpblocks.o: define.h getidblock.o: XGetopt.h define.h libpst.h libpst.o: define.h libstrfunc.h libpst.h timeconv.h libstrfunc.o: libstrfunc.h lspst.o: libpst.h timeconv.h lzfu.o: define.h libpst.h lzfu.h readpst.o: XGetopt.h libstrfunc.h define.h libpst.h common.h timeconv.h lzfu.h pst2ldif.o: XGetopt.h libstrfunc.h define.h libpst.h common.h timeconv.h lzfu.h nick2ldif.o: XGetopt.h libstrfunc.h define.h libpst.h common.h timeconv.h lzfu.h readpstlog.o: XGetopt.h define.h testdebug.o: define.h timeconv.o: timeconv.h common.h readpst: readpst.o libpst.o timeconv.o libstrfunc.o debug.o lzfu.o pst2ldif: pst2ldif.o libpst.o timeconv.o libstrfunc.o debug.o lzfu.o -nick2ldif: nick2ldif.o libpst.o timeconv.o libstrfunc.o debug.o lzfu.o lspst: debug.o libpst.o libstrfunc.o lspst.o timeconv.o getidblock: getidblock.o libpst.o debug.o libstrfunc.o testdebug: testdebug.o debug.o readpstlog: readpstlog.o debug.o dumpblocks: dumpblocks.o libpst.o debug.o libstrfunc.o +nick2ldif: nick2ldif.o libpst.o timeconv.o libstrfunc.o debug.o lzfu.o + g++ ${CFLAGS} nick2ldif.cpp -o nick2ldif libpst.o timeconv.o libstrfunc.o debug.o lzfu.o + clean: rm -f core *.o readpst.log $(ALL_PROGS) *~ MANIFEST distclean: clean rm -f libpst-*.tar.gz install: all $(INSTALL_DIR) $(DESTDIR)$(PREFIX)/bin $(INSTALL_PROGRAM) readpst{,log} $(DESTDIR)$(PREFIX)/bin $(INSTALL_DIR) $(DESTDIR)$(PREFIX)/share/man/man1 $(INSTALL_FILE) readpst{,log}.1 $(DESTDIR)$(PREFIX)/share/man/man1/ $(INSTALL_DIR) $(DESTDIR)$(PREFIX)/share/doc/libpst $(INSTALL_FILE) $(DOCS) $(DESTDIR)$(PREFIX)/share/doc/libpst/ uninstall: -rm -f $(DESTDIR)$(PREFIX)/bin/readpst{,log} -rm -f $(DESTDIR)$(PREFIX)/share/man/man1/readpst{,log}.1 # stolen from ESR's Software Release Practices HOWTO available at: # http://en.tldp.org/HOWTO/Software-Release-Practice-HOWTO/distpractice.html MANIFEST: Makefile @ls $(DISTFILES) | sed s:^:libpst-$(VERSION)/: >MANIFEST tarball libpst-$(VERSION).tar.gz: MANIFEST $(DISTFILES) @(cd ..; ln -s libpst libpst-$(VERSION)) (cd ..; tar -czvf libpst/libpst-$(VERSION).tar.gz `cat libpst/MANIFEST`) @(cd ..; rm libpst-$(VERSION)) @rm -f MANIFEST .PHONY: clean distclean uninstall install tarball diff --git a/define.h b/define.h index ddb6edb..4c671ba 100644 --- a/define.h +++ b/define.h @@ -1,201 +1,201 @@ /*** * define.h * Part of the LibPST project * Written by David Smith * dave.s@earthcorp.com */ //#define DEBUG_ALL #ifndef DEFINEH_H #define DEFINEH_H #ifdef DEBUG_ALL #define DEBUG_MODE_GEN #define DEBUGPRINT #define DEBUG_MODE_WARN #define DEBUG_MODE_READ #define DEBUG_MODE_EMAIL #define DEBUG_MODE_MAIN #define DEBUG_MODE_INDEX #define DEBUG_MODE_CODE #define DEBUG_MODE_INFO #define DEBUG_MODE_HEXDUMP #define DEBUG_MODE_FUNC //#define DEBUG_MODE_DECRYPT #endif //number of items to save in memory between writes #define DEBUG_MAX_ITEMS 0 #define DEBUG_FILE_NO 1 #define DEBUG_INDEX_NO 2 #define DEBUG_EMAIL_NO 3 #define DEBUG_WARN_NO 4 #define DEBUG_READ_NO 5 #define DEBUG_INFO_NO 6 #define DEBUG_MAIN_NO 7 #define DEBUG_DECRYPT_NO 8 #define DEBUG_FUNC_NO 10 #define DEBUG_HEXDUMP_NO 11 -//variable number of arguments to this macro. will expand them into +//variable number of arguments to this macro. will expand them into // ## args, then exit with status of 1 #include #include #include #ifdef __LINUX__ #include #include #endif void _pst_debug(char *fmt, ...); void _pst_debug_hexdump(FILE* out, unsigned char* buf, size_t size, int col); void _pst_debug_hexprint(char *data, int size); void _debug_init(char *fname); void _debug_msg_info (int line, char *file, int type); void _debug_msg_text(char* fmt, ...); void _debug_hexdump(char *x, int y, int cols); void _debug_func(char *function); void _debug_func_ret(); void _debug_close(void); void _debug_write(); void * xmalloc(size_t size); #define MESSAGEPRINT(x,y) {_debug_msg_info(__LINE__,__FILE__,y);\ _debug_msg_text x;} #define LOGSTOP() {MESSAGESTOP();DEBUGSTOP();} #define DIE(x) {\ MESSAGEPRINT(x, 0);\ printf x;\ exit(EXIT_FAILURE);\ } #define WARN(x) {\ MESSAGEPRINT(x, 0);\ printf x;\ } #ifdef DEBUGPRINT #define DEBUG_PRINT(x) _pst_debug x; #else #define DEBUG_PRINT(x) {} #endif #ifdef DEBUG_MODE_GEN #define DEBUG(x) {DEBUG_PRINT(x);} #else #define DEBUG(x) {} #endif #ifdef DEBUG_MODE_INDEX #define DEBUG_INDEX(x) MESSAGEPRINT(x, DEBUG_INDEX_NO); #else #define DEBUG_INDEX(x) {} #endif #ifdef DEBUG_MODE_EMAIL #define DEBUG_EMAIL(x) MESSAGEPRINT(x, DEBUG_EMAIL_NO); #define DEBUG_EMAIL_HEXPRINT(x,y) {_debug_msg_info(__LINE__, __FILE__, 11);\ _debug_hexdump(x, y, 0x10);} #else #define DEBUG_EMAIL(x) {} #define DEBUG_EMAIL_HEXPRINT(x,y) {} #endif #ifdef DEBUG_MODE_WARN #define DEBUG_WARN(x) MESSAGEPRINT(x, DEBUG_WARN_NO); #else #define DEBUG_WARN(x) {} #endif #ifdef DEBUG_MODE_READ #define DEBUG_READ(x) MESSAGEPRINT(x, DEBUG_READ_NO); #else #define DEBUG_READ(x) {} #endif #ifdef DEBUG_MODE_INFO #define DEBUG_INFO(x) MESSAGEPRINT(x, DEBUG_INFO_NO); #else #define DEBUG_INFO(x) {} #endif #ifdef DEBUG_MODE_MAIN #define DEBUG_MAIN(x) MESSAGEPRINT(x, DEBUG_MAIN_NO); #else #define DEBUG_MAIN(x) {} #endif #ifdef DEBUG_MODE_CODE #define DEBUG_CODE(x) {x} #else #define DEBUG_CODE(x) {} #endif #ifdef DEBUG_MODE_DECRYPT #define DEBUG_DECRYPT(x) MESSAGEPRINT(x, DEBUG_DECRYPT_NO); #else #define DEBUG_DECRYPT(x) {} #endif #ifdef DEBUG_MODE_HEXDUMP #define DEBUG_HEXDUMP(x, s)\ {_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\ _debug_hexdump(x, s, 0x10);} #define DEBUG_HEXDUMPC(x, s, c)\ {_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\ _debug_hexdump(x, s, c);} #else #define DEBUG_HEXDUMP(x, s) {} #define DEBUG_HEXDUMPC(x, s, c) {} #endif #define DEBUG_FILE(x) {_debug_msg_info(__LINE__, __FILE__, DEBUG_FILE_NO);\ _debug_msg_text x;} #ifdef DEBUG_MODE_FUNC # define DEBUG_ENT(x) \ {MESSAGEPRINT(("Entering function %s\n",x),DEBUG_FUNC_NO);\ _debug_func(x);} # define DEBUG_RET() {MESSAGEPRINT(("Leaving function\n"),DEBUG_FUNC_NO);\ _debug_func_ret();} #else # define DEBUG_ENT(x) {} # define DEBUG_RET() {} #endif #define DEBUG_INIT(fname) {_debug_init(fname);} #define DEBUG_CLOSE() {_debug_close();} #define DEBUG_REGISTER_CLOSE() {if(atexit(_debug_close)!=0) fprintf(stderr, "Error registering atexit function\n");} #define RET_DERROR(res, ret_val, x)\ if (res) { DIE(x);} #define RET_ERROR(res, ret_val)\ if (res) {return ret_val;} #define DEBUG_VERSION 1 struct _debug_file_rec_m { unsigned short int funcname; unsigned short int filename; unsigned short int text; unsigned short int end; unsigned int line; unsigned int type; }; struct _debug_file_rec_l { unsigned int funcname; unsigned int filename; unsigned int text; unsigned int end; unsigned int line; unsigned int type; }; #endif //DEFINEH_H diff --git a/pst2ldif.c b/pst2ldif.c index 1592d08..062731b 100644 --- a/pst2ldif.c +++ b/pst2ldif.c @@ -1,423 +1,527 @@ /* Copyright (c) 2004 Carl Byington - 510 Software Group, released under the GPL version 2 or any later version at your choice available at http://www.fsf.org/licenses/gpl.txt Based on readpst.c by David Smith */ #include #include #include #include #include #include #include #ifndef _WIN32 # include # include //mkdir // for reading of directory and clearing in function mk_separate_dir # include # include #else # include # define chdir _chdir # define int32_t __int32 #endif #ifndef __GNUC__ # include "XGetopt.h" #endif #include "libstrfunc.h" // for base64_encoding #include "define.h" #include "libpst.h" #include "common.h" #include "timeconv.h" #include "lzfu.h" #define OUTPUT_TEMPLATE "%s" -#define VERSION "0.1" +#define VERSION "0.2" // max size of the c_time char*. It will store the date of the email #define C_TIME_SIZE 500 #define PERM_DIRS 0777 // macro used for creating directories #ifndef WIN32 #define D_MKDIR(x) mkdir(x, PERM_DIRS) #else #define D_MKDIR(x) mkdir(x) #endif int32_t usage(); int32_t version(); char *my_stristr(char *haystack, char *needle); char *check_filename(char *fname); char *single(char *str); -char *multi(char *fmt, char *str); +char *folded(char *str); +void multi(char *fmt, char *str); char *rfc2426_escape(char *str); int32_t chr_count(char *str, char x); char *prog_name; pst_file pstfile; char *ldap_base = NULL; // 'o=some.domain.tld, c=US' char *ldap_class = NULL; // 'newPerson' char *ldap_org = NULL; // 'o=some.domain.tld', computed from ldap_base char *trim(char *name); char *trim(char *name) { char *p; while (*name == ' ') name++; p = name + strlen(name) - 1; while ((p >= name) && (*p == ' ')) *p-- = '\0'; return name; } void process(pst_desc_ll *d_ptr); void process(pst_desc_ll *d_ptr) { pst_item *item = NULL; while (d_ptr) { if (d_ptr->desc) { item = _pst_parse_item(&pstfile, d_ptr); if (item) { if (item->message_store) { // there should only be one message_store, and we have already done it DIE(("main: A second message_store has been found. Sorry, this must be an error.\n")); } - if (item->folder) { //if this is a folder, we want to recurse into it + if (item->folder && d_ptr->child && strcasecmp(item->file_as, "Deleted Items")) { + //if this is a non-empty folder other than deleted items, we want to recurse into it + fprintf(stderr, "entering folder %s\n", item->file_as); process(d_ptr->child); } else if (item->contact) { // deal with a contact if (item->type != PST_TYPE_CONTACT) { DIE(("type should be contact\n")); } else if (item->contact == NULL) { // this is an incorrect situation. Inform user DIE(("null item contact\n")); } else { char cn[1000]; snprintf(cn, sizeof(cn), "%s %s %s %s", single(item->contact->display_name_prefix), single(item->contact->first_name), single(item->contact->surname), single(item->contact->suffix)); if (strcmp(cn, " ")) { +// fprintf(stderr, "\n\n\n"); +// fprintf(stderr, "access_method %s\n", item->contact->access_method); +// fprintf(stderr, "account_name %s\n", item->contact->account_name); +// fprintf(stderr, "address1 %s\n", item->contact->address1); +// fprintf(stderr, "address1_desc %s\n", item->contact->address1_desc); +// fprintf(stderr, "address1_transport %s\n", item->contact->address1_transport); +// fprintf(stderr, "address2 %s\n", item->contact->address2); +// fprintf(stderr, "address2_desc %s\n", item->contact->address2_desc); +// fprintf(stderr, "address2_transport %s\n", item->contact->address2_transport); +// fprintf(stderr, "address3 %s\n", item->contact->address3); +// fprintf(stderr, "address3_desc %s\n", item->contact->address3_desc); +// fprintf(stderr, "address3_transport %s\n", item->contact->address3_transport); +// fprintf(stderr, "assistant_name %s\n", item->contact->assistant_name); +// fprintf(stderr, "assistant_phone %s\n", item->contact->assistant_phone); +// fprintf(stderr, "billing_information %s\n", item->contact->billing_information); +// fprintf(stderr, "business_address %s\n", item->contact->business_address); +// fprintf(stderr, "business_city %s\n", item->contact->business_city); +// fprintf(stderr, "business_country %s\n", item->contact->business_country); +// fprintf(stderr, "business_fax %s\n", item->contact->business_fax); +// fprintf(stderr, "business_homepage %s\n", item->contact->business_homepage); +// fprintf(stderr, "business_phone %s\n", item->contact->business_phone); +// fprintf(stderr, "business_phone2 %s\n", item->contact->business_phone2); +// fprintf(stderr, "business_po_box %s\n", item->contact->business_po_box); +// fprintf(stderr, "business_postal_code %s\n", item->contact->business_postal_code); +// fprintf(stderr, "business_state %s\n", item->contact->business_state); +// fprintf(stderr, "business_street %s\n", item->contact->business_street); +// fprintf(stderr, "callback_phone %s\n", item->contact->callback_phone); +// fprintf(stderr, "car_phone %s\n", item->contact->car_phone); +// fprintf(stderr, "company_main_phone %s\n", item->contact->company_main_phone); +// fprintf(stderr, "company_name %s\n", item->contact->company_name); +// fprintf(stderr, "computer_name %s\n", item->contact->computer_name); +// fprintf(stderr, "customer_id %s\n", item->contact->customer_id); +// fprintf(stderr, "def_postal_address %s\n", item->contact->def_postal_address); +// fprintf(stderr, "department %s\n", item->contact->department); +// fprintf(stderr, "display_name_prefix %s\n", item->contact->display_name_prefix); +// fprintf(stderr, "first_name %s\n", item->contact->first_name); +// fprintf(stderr, "followup %s\n", item->contact->followup); +// fprintf(stderr, "free_busy_address %s\n", item->contact->free_busy_address); +// fprintf(stderr, "ftp_site %s\n", item->contact->ftp_site); +// fprintf(stderr, "fullname %s\n", item->contact->fullname); +// fprintf(stderr, "gov_id %s\n", item->contact->gov_id); +// fprintf(stderr, "hobbies %s\n", item->contact->hobbies); +// fprintf(stderr, "home_address %s\n", item->contact->home_address); +// fprintf(stderr, "home_city %s\n", item->contact->home_city); +// fprintf(stderr, "home_country %s\n", item->contact->home_country); +// fprintf(stderr, "home_fax %s\n", item->contact->home_fax); +// fprintf(stderr, "home_phone %s\n", item->contact->home_phone); +// fprintf(stderr, "home_phone2 %s\n", item->contact->home_phone2); +// fprintf(stderr, "home_po_box %s\n", item->contact->home_po_box); +// fprintf(stderr, "home_postal_code %s\n", item->contact->home_postal_code); +// fprintf(stderr, "home_state %s\n", item->contact->home_state); +// fprintf(stderr, "home_street %s\n", item->contact->home_street); +// fprintf(stderr, "initials %s\n", item->contact->initials); +// fprintf(stderr, "isdn_phone %s\n", item->contact->isdn_phone); +// fprintf(stderr, "job_title %s\n", item->contact->job_title); +// fprintf(stderr, "keyword %s\n", item->contact->keyword); +// fprintf(stderr, "language %s\n", item->contact->language); +// fprintf(stderr, "location %s\n", item->contact->location); +// fprintf(stderr, "manager_name %s\n", item->contact->manager_name); +// fprintf(stderr, "middle_name %s\n", item->contact->middle_name); +// fprintf(stderr, "mileage %s\n", item->contact->mileage); +// fprintf(stderr, "mobile_phone %s\n", item->contact->mobile_phone); +// fprintf(stderr, "nickname %s\n", item->contact->nickname); +// fprintf(stderr, "office_loc %s\n", item->contact->office_loc); +// fprintf(stderr, "org_id %s\n", item->contact->org_id); +// fprintf(stderr, "other_address %s\n", item->contact->other_address); +// fprintf(stderr, "other_city %s\n", item->contact->other_city); +// fprintf(stderr, "other_country %s\n", item->contact->other_country); +// fprintf(stderr, "other_phone %s\n", item->contact->other_phone); +// fprintf(stderr, "other_po_box %s\n", item->contact->other_po_box); +// fprintf(stderr, "other_postal_code %s\n", item->contact->other_postal_code); +// fprintf(stderr, "other_state %s\n", item->contact->other_state); +// fprintf(stderr, "other_street %s\n", item->contact->other_street); +// fprintf(stderr, "pager_phone %s\n", item->contact->pager_phone); +// fprintf(stderr, "personal_homepage %s\n", item->contact->personal_homepage); +// fprintf(stderr, "pref_name %s\n", item->contact->pref_name); +// fprintf(stderr, "primary_fax %s\n", item->contact->primary_fax); +// fprintf(stderr, "primary_phone %s\n", item->contact->primary_phone); +// fprintf(stderr, "profession %s\n", item->contact->profession); +// fprintf(stderr, "radio_phone %s\n", item->contact->radio_phone); +// fprintf(stderr, "spouse_name %s\n", item->contact->spouse_name); +// fprintf(stderr, "suffix %s\n", item->contact->suffix); +// fprintf(stderr, "surname %s\n", item->contact->surname); +// fprintf(stderr, "telex %s\n", item->contact->telex); +// fprintf(stderr, "transmittable_display_name %s\n", item->contact->transmittable_display_name); +// fprintf(stderr, "ttytdd_phone %s\n", item->contact->ttytdd_phone); // have a valid cn printf("dn: cn=%s, %s\n", trim(cn), ldap_base); printf("cn: %s\n", trim(cn)); if (item->contact->first_name) { snprintf(cn, sizeof(cn), "%s %s", single(item->contact->display_name_prefix), single(item->contact->first_name)); printf("givenName: %s\n", trim(cn)); } if (item->contact->surname) { snprintf(cn, sizeof(cn), "%s %s", single(item->contact->surname), single(item->contact->suffix)); printf("sn: %s\n", trim(cn)); } if (item->contact->job_title) printf("personalTitle: %s\n", single(item->contact->job_title)); if (item->contact->company_name) printf("company: %s\n", single(item->contact->company_name)); if (item->contact->address1) printf("mail: %s\n", single(item->contact->address1)); if (item->contact->address2) printf("mail: %s\n", single(item->contact->address2)); if (item->contact->address3) printf("mail: %s\n", single(item->contact->address3)); if (item->contact->business_address) { if (item->contact->business_po_box) printf("postalAddress: %s\n", single(item->contact->business_po_box)); if (item->contact->business_street) multi("postalAddress: %s\n", item->contact->business_street); if (item->contact->business_city) printf("l: %s\n", single(item->contact->business_city)); if (item->contact->business_state) printf("st: %s\n", single(item->contact->business_state)); if (item->contact->business_postal_code) printf("postalCode: %s\n", single(item->contact->business_postal_code)); } else if (item->contact->home_address) { if (item->contact->home_po_box) printf("postalAddress: %s\n", single(item->contact->home_po_box)); if (item->contact->home_street) multi("postalAddress: %s\n", item->contact->home_street); if (item->contact->home_city) printf("l: %s\n", single(item->contact->home_city)); if (item->contact->home_state) printf("st: %s\n", single(item->contact->home_state)); if (item->contact->home_postal_code) printf("postalCode: %s\n", single(item->contact->home_postal_code)); } else if (item->contact->other_address) { if (item->contact->other_po_box) printf("postalAddress: %s\n", single(item->contact->other_po_box)); if (item->contact->other_street) multi("postalAddress: %s\n", item->contact->other_street); if (item->contact->other_city) printf("l: %s\n", single(item->contact->other_city)); if (item->contact->other_state) printf("st: %s\n", single(item->contact->other_state)); if (item->contact->other_postal_code) printf("postalCode: %s\n", single(item->contact->other_postal_code)); } if (item->contact->business_fax) printf("facsimileTelephoneNumber: %s\n", single(item->contact->business_fax)); else if (item->contact->home_fax) printf("facsimileTelephoneNumber: %s\n", single(item->contact->home_fax)); if (item->contact->business_phone) printf("telephoneNumber: %s\n", single(item->contact->business_phone)); if (item->contact->home_phone) printf("homePhone: %s\n", single(item->contact->home_phone)); if (item->contact->car_phone) printf("mobile: %s\n", single(item->contact->car_phone)); else if (item->contact->mobile_phone) printf("mobile: %s\n", single(item->contact->mobile_phone)); else if (item->contact->other_phone) printf("mobile: %s\n", single(item->contact->other_phone)); if (item->comment) printf("description: %s\n", single(item->comment)); printf("objectClass: %s\n\n", ldap_class); } } } } _pst_freeItem(item); } d_ptr = d_ptr->next; } } int main(int argc, char** argv) { pst_desc_ll *d_ptr; char *fname = NULL; char *temp = NULL; //temporary char pointer char c; prog_name = argv[0]; pst_item *item = NULL; while ((c = getopt(argc, argv, "b:c:Vh"))!= -1) { switch (c) { case 'b': ldap_base = optarg; temp = strchr(ldap_base, ','); if (temp) { *temp = '\0'; ldap_org = strdup(ldap_base); *temp = ','; } break; case 'c': ldap_class = optarg; break; case 'h': usage(); exit(0); break; case 'V': version(); exit(0); break; default: usage(); exit(1); break; } } if ((argc > optind) && (ldap_base) && (ldap_class) && (ldap_org)) { fname = argv[optind]; } else { usage(); exit(2); } DEBUG_INIT("pst2ldif.log"); DEBUG_REGISTER_CLOSE(); DEBUG_ENT("main"); RET_DERROR(pst_open(&pstfile, fname, "r"), 1, ("Error opening File\n")); RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n")); pst_load_extended_attributes(&pstfile); d_ptr = pstfile.d_head; // first record is main record item = _pst_parse_item(&pstfile, d_ptr); if (!item || !item->message_store) { DIE(("main: Could not get root record\n")); } d_ptr = pst_getTopOfFolders(&pstfile, item); if (!d_ptr) { DIE(("Top of folders record not found. Cannot continue\n")); } _pst_freeItem(item); // write the ldap header printf("dn: %s\n", ldap_base); printf("o: %s\n", ldap_org); printf("objectClass: organization\n\n"); printf("dn: cn=root, %s\n", ldap_base); printf("cn: root\n"); printf("objectClass: %s\n\n", ldap_class); process(d_ptr->child); // do the children of TOPF pst_close(&pstfile); return 0; } int usage() { version(); printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name); printf("OPTIONS:\n"); printf("\t-h\t- Help. This screen\n"); printf("\t-V\t- Version. Display program version\n"); printf("\t-b ldapbase\t- set the ldap base value\n"); printf("\t-c class \t- set the class of the ldap objects\n"); return 0; } int version() { printf("pst2ldif v%s using LibPST v%s\n", VERSION, PST_VERSION); #if BYTE_ORDER == BIG_ENDIAN printf("Big Endian implementation being used.\n"); #elif BYTE_ORDER == LITTLE_ENDIAN printf("Little Endian implementation being used.\n"); #else # error "Byte order not supported by this library" #endif #ifdef __GNUC__ printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__); #endif return 0; } // my_stristr varies from strstr in that its searches are case-insensitive char * my_stristr(char *haystack, char *needle) { char *x=haystack, *y=needle, *z = NULL; if (haystack == NULL || needle == NULL) return NULL; while (*y != '\0' && *x != '\0') { if (tolower(*y) == tolower(*x)) { // move y on one y++; if (z == NULL) { z = x; // store first position in haystack where a match is made } } else { y = needle; // reset y to the beginning of the needle z = NULL; // reset the haystack storage point } x++; // advance the search in the haystack } return z; } char *check_filename(char *fname) { char *t = fname; if (t == NULL) { return fname; } while ((t = strpbrk(t, "/\\:"))) { // while there are characters in the second string that we don't want *t = '_'; //replace them with an underscore } return fname; } char *single(char *str) { if (!str) return ""; char *ret = rfc2426_escape(str); char *n = strchr(ret, '\n'); if (n) *n = '\0'; return ret; } -char *multi(char *fmt, char *str) { +char *folded(char *str) { if (!str) return ""; char *ret = rfc2426_escape(str); char *n = ret; + while (n = strchr(n, '\n')) { + *n = ' '; + } + n = ret; + while (n = strchr(n, ',')) { + *n = ' '; + } + return ret; +} + + +void multi(char *fmt, char *str) { + if (!str) return; + char *ret = rfc2426_escape(str); + char *n = ret; while (n = strchr(ret, '\n')) { *n = '\0'; printf(fmt, ret); ret = n+1; } if (*ret) printf(fmt, ret); } char *rfc2426_escape(char *str) { static char* buf = NULL; char *ret, *a, *b; int x = 0, y, z; if (str == NULL) ret = str; else { // calculate space required to escape all the following characters x = strlen(str) +(y=(chr_count(str, ',')*2) + (chr_count(str, '\\')*2) + (chr_count(str, ';')*2) + (chr_count(str, '\n')*2)); z = chr_count(str, '\r'); if (y == 0 && z == 0) // there isn't any extra space required ret = str; else { buf = (char*) realloc(buf, x+1); a = str; b = buf; while (*a != '\0') { switch(*a) { // case ',' : case '\\': case ';' : // case '\n': *(b++)='\\'; *b=*a; break; case '\r': break; default: *b=*a; } b++; a++; } *b = '\0'; ret = buf; } } return ret; } int chr_count(char *str, char x) { int r = 0; while (*str != '\0') { if (*str == x) r++; str++; } return r; }