annotate src/nick2ldif.cpp @ 377:506e266f930d

Vitaliy Didik - fix MSVC build
author Carl Byington <carl@five-ten-sg.com>
date Mon, 20 Nov 2017 08:19:28 -0800
parents 8ad8fd1c5451
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1 /*
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
2
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
3 Copyright (c) 2004 Carl Byington - 510 Software Group, released under
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
4 the GPL version 2 or any later version at your choice available at
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
5 http://www.fsf.org/licenses/gpl.txt
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
6
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
7 */
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
8
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
9 #include <iostream>
123
ab2a11e72250 more cleanup of #include files.
Carl Byington <carl@five-ten-sg.com>
parents: 118
diff changeset
10
118
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 21
diff changeset
11 extern "C" {
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 21
diff changeset
12 #include "define.h"
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 21
diff changeset
13 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
14
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
15 char *ldap_base = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
16 char *ldap_org = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
17 char *ldap_class = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
18
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
19 using namespace std;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
20
258
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
21 int main(int argc, char* const* argv) {
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
22 char c;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
23 char *temp;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
24 while ((c = getopt(argc, argv, "b:c:"))!= -1) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
25 switch (c) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
26 case 'b':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
27 ldap_base = optarg;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
28 temp = strchr(ldap_base, ',');
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
29 if (temp) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
30 *temp = '\0';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
31 ldap_org = strdup(ldap_base);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
32 *temp = ',';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
33 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
34 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
35 case 'c':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
36 ldap_class = optarg;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
37 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
38 default:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
39 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
40 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
41 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
42
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
43 const int LINE_SIZE = 2000;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
44 char line[LINE_SIZE];
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
45 while (!cin.eof()) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
46 cin.getline(line, LINE_SIZE);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
47 int n = strlen(line);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
48 if (!n) continue;
258
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
49 if (strncmp(line, "alias", 5) != 0) continue; // not alias
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
50 char *f = line + 6; // skip alias keyword
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
51 char *e;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
52 if (*f == '"') {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
53 f++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
54 e = strchr(f, '"');
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
55 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
56 else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
57 e = strchr(f, ' ');
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
58 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
59 if (!e) continue;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
60 *e = '\0';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
61 char *m = e+1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
62 while (*m == ' ') m++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
63 if (*m != '\0') {
258
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
64 char cn[1000], givenName[1000], sn[1000];
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
65 snprintf(cn, sizeof(cn), "%s", f);
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
66 char *ff = strchr(f, ' ');
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
67 if (ff) {
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
68 strncpy(givenName, ff+1, sizeof(givenName)-1);
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
69 *ff = '\0';
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
70 strncpy(sn, f, sizeof(sn)-1);
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
71 }
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
72 else {
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
73 strcpy(givenName, cn);
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
74 strcpy(sn, cn);
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
75 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
76 printf("dn: cn=%s, %s\n", cn, ldap_base);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
77 printf("cn: %s\n", cn);
258
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
78 printf("givenName: %s\n", givenName);
8ad8fd1c5451 check return codes from forked processes
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
79 printf("sn: %s\n", sn);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
80 printf("mail: %s\n", m);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
81 printf("objectClass: %s\n\n", ldap_class);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
82 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
83 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
84 }