annotate nick2ldif.cpp @ 9:8c724896a28a

changes for ldap v3, needs o:value not o:o=value
author carl
date Sun, 31 Jul 2005 18:41:06 -0700
parents 8dd68d722fa8
children a818f3c2e589
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
1 /*
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
2
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
3 Copyright (c) 2004 Carl Byington - 510 Software Group, released under
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
4 the GPL version 2 or any later version at your choice available at
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
5 http://www.fsf.org/licenses/gpl.txt
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
6
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
7 */
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
8
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
9 #include <stdio.h>
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
10 #include <iostream>
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
11 //#include <fstream>
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
12 #include <unistd.h>
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
13
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
14 char *ldap_base = NULL;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
15 char *ldap_org = NULL;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
16 char *ldap_class = NULL;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
17
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
18 using namespace std;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
19
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
20 int main(int argc, char** argv) {
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
21 char c;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
22 char *temp;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
23 while ((c = getopt(argc, argv, "b:c:"))!= -1) {
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
24 switch (c) {
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
25 case 'b':
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
26 ldap_base = optarg;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
27 temp = strchr(ldap_base, ',');
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
28 if (temp) {
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
29 *temp = '\0';
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
30 ldap_org = strdup(ldap_base);
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
31 *temp = ',';
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
32 }
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
33 break;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
34 case 'c':
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
35 ldap_class = optarg;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
36 break;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
37 default:
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
38 break;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
39 }
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
40 }
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
41
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
42 char *delim = " \t";
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
43 const int LINE_SIZE = 2000;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
44 char line[LINE_SIZE];
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
45 while (!cin.eof()) {
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
46 cin.getline(line, LINE_SIZE);
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
47 int n = strlen(line);
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
48 if (!n) continue;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
49 char *f = line + 6; // skip alias keyword
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
50 char *e;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
51 if (*f == '"') {
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
52 f++;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
53 e = strchr(f, '"');
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
54 }
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
55 else {
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
56 e = strchr(f, ' ');
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
57 }
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
58 if (!e) continue;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
59 *e = '\0';
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
60 char *m = e+1;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
61 while (*m == ' ') m++;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
62 if (*m != '\0') {
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
63 char cn[1000];
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
64 snprintf(cn, sizeof(cn), "email %s", f);
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
65 printf("dn: cn=%s, %s\n", cn, ldap_base);
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
66 printf("cn: %s\n", cn);
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
67 printf("sn: %s\n", f);
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
68 printf("mail: %s\n", m);
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
69 printf("objectClass: %s\n\n", ldap_class);
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
70 }
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
71 }
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
72 }