Main Page | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

nick2ldif.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (c) 2004 Carl Byington - 510 Software Group, released under
00004 the GPL version 2 or any later version at your choice available at
00005 http://www.fsf.org/licenses/gpl.txt
00006 
00007 */
00008 
00009 #include <iostream>
00010 
00011 extern "C" {
00012     #include "define.h"
00013 }
00014 
00015 char *ldap_base  = NULL;
00016 char *ldap_org   = NULL;
00017 char *ldap_class = NULL;
00018 
00019 using namespace std;
00020 
00021 int main(int argc, const char** argv) {
00022     char c;
00023     char *temp;
00024     while ((c = getopt(argc, argv, "b:c:"))!= -1) {
00025         switch (c) {
00026         case 'b':
00027             ldap_base = optarg;
00028             temp = strchr(ldap_base, ',');
00029             if (temp) {
00030                 *temp = '\0';
00031                 ldap_org = strdup(ldap_base);
00032                 *temp = ',';
00033             }
00034             break;
00035         case 'c':
00036             ldap_class = optarg;
00037             break;
00038         default:
00039             break;
00040         }
00041     }
00042 
00043     const int LINE_SIZE = 2000;
00044     char line[LINE_SIZE];
00045     while (!cin.eof()) {
00046         cin.getline(line, LINE_SIZE);
00047         int n = strlen(line);
00048         if (!n) continue;
00049         char *f = line + 6;     // skip alias keyword
00050         char *e;
00051         if (*f == '"') {
00052             f++;
00053             e = strchr(f, '"');
00054         }
00055         else {
00056             e = strchr(f, ' ');
00057         }
00058         if (!e) continue;
00059         *e = '\0';
00060         char *m = e+1;
00061         while (*m == ' ') m++;
00062         if (*m != '\0') {
00063             char cn[1000];
00064             snprintf(cn, sizeof(cn), "email %s", f);
00065             printf("dn: cn=%s, %s\n", cn, ldap_base);
00066             printf("cn: %s\n", cn);
00067             printf("sn: %s\n", f);
00068             printf("mail: %s\n", m);
00069             printf("objectClass: %s\n\n", ldap_class);
00070         }
00071     }
00072 }

Generated on Thu Feb 26 13:40:07 2009 for 'LibPst' by  doxygen 1.3.9.1