comparison nick2ldif.cpp @ 2:8dd68d722fa8

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