'LibPst'
nick2ldif.cpp
Go to the documentation of this file.
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 <iostream>
10
11
extern
"C"
{
12
#include "
define.h
"
13
}
14
15
char
*
ldap_base
= NULL;
16
char
*
ldap_org
= NULL;
17
char
*
ldap_class
= NULL;
18
19
using namespace
std
;
20
21
int
main
(
int
argc,
char
*
const
* argv) {
22
char
c;
23
char
*temp;
24
while
((c =
getopt
(argc, argv,
"b:c:"
))!= -1) {
25
switch
(c) {
26
case
'b'
:
27
ldap_base
=
optarg
;
28
temp = strchr(
ldap_base
,
','
);
29
if
(temp) {
30
*temp =
'\0'
;
31
ldap_org
= strdup(
ldap_base
);
32
*temp =
','
;
33
}
34
break
;
35
case
'c'
:
36
ldap_class
=
optarg
;
37
break
;
38
default
:
39
break
;
40
}
41
}
42
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
if
(strncmp(line,
"alias"
, 5) != 0)
continue
;
// not alias
50
char
*f = line + 6;
// skip alias keyword
51
char
*e;
52
if
(*f ==
'"'
) {
53
f++;
54
e = strchr(f,
'"'
);
55
}
56
else
{
57
e = strchr(f,
' '
);
58
}
59
if
(!e)
continue
;
60
*e =
'\0'
;
61
char
*m = e+1;
62
while
(*m ==
' '
) m++;
63
if
(*m !=
'\0'
) {
64
char
cn[1000], givenName[1000], sn[1000];
65
snprintf(cn,
sizeof
(cn),
"%s"
, f);
66
char
*ff = strchr(f,
' '
);
67
if
(ff) {
68
strncpy(givenName, ff+1,
sizeof
(givenName)-1);
69
*ff =
'\0'
;
70
strncpy(sn, f,
sizeof
(sn)-1);
71
}
72
else
{
73
strcpy(givenName, cn);
74
strcpy(sn, cn);
75
}
76
printf(
"dn: cn=%s, %s\n"
, cn,
ldap_base
);
77
printf(
"cn: %s\n"
, cn);
78
printf(
"givenName: %s\n"
, givenName);
79
printf(
"sn: %s\n"
, sn);
80
printf(
"mail: %s\n"
, m);
81
printf(
"objectClass: %s\n\n"
,
ldap_class
);
82
}
83
}
84
}
ldap_base
char * ldap_base
Definition:
nick2ldif.cpp:15
ldap_class
char * ldap_class
Definition:
nick2ldif.cpp:17
std
getopt
int getopt(int argc, char *const *argv, char *optstring)
Definition:
XGetopt.c:139
LINE_SIZE
const int LINE_SIZE
Definition:
pst2dii.cpp:69
ldap_org
char * ldap_org
Definition:
nick2ldif.cpp:16
main
int main(int argc, char *const *argv)
Definition:
nick2ldif.cpp:21
optarg
char * optarg
Definition:
XGetopt.c:136
define.h
src
nick2ldif.cpp
Generated by
1.8.14