comparison src/nick2ldif.cpp @ 258:8ad8fd1c5451

check return codes from forked processes
author Carl Byington <carl@five-ten-sg.com>
date Sat, 16 Apr 2011 10:09:28 -0700
parents fc11b1d1ad34
children
comparison
equal deleted inserted replaced
257:c947b8812120 258:8ad8fd1c5451
16 char *ldap_org = NULL; 16 char *ldap_org = NULL;
17 char *ldap_class = NULL; 17 char *ldap_class = NULL;
18 18
19 using namespace std; 19 using namespace std;
20 20
21 int main(int argc, const char** argv) { 21 int main(int argc, char* const* argv) {
22 char c; 22 char c;
23 char *temp; 23 char *temp;
24 while ((c = getopt(argc, argv, "b:c:"))!= -1) { 24 while ((c = getopt(argc, argv, "b:c:"))!= -1) {
25 switch (c) { 25 switch (c) {
26 case 'b': 26 case 'b':
44 char line[LINE_SIZE]; 44 char line[LINE_SIZE];
45 while (!cin.eof()) { 45 while (!cin.eof()) {
46 cin.getline(line, LINE_SIZE); 46 cin.getline(line, LINE_SIZE);
47 int n = strlen(line); 47 int n = strlen(line);
48 if (!n) continue; 48 if (!n) continue;
49 if (strncmp(line, "alias", 5) != 0) continue; // not alias
49 char *f = line + 6; // skip alias keyword 50 char *f = line + 6; // skip alias keyword
50 char *e; 51 char *e;
51 if (*f == '"') { 52 if (*f == '"') {
52 f++; 53 f++;
53 e = strchr(f, '"'); 54 e = strchr(f, '"');
58 if (!e) continue; 59 if (!e) continue;
59 *e = '\0'; 60 *e = '\0';
60 char *m = e+1; 61 char *m = e+1;
61 while (*m == ' ') m++; 62 while (*m == ' ') m++;
62 if (*m != '\0') { 63 if (*m != '\0') {
63 char cn[1000]; 64 char cn[1000], givenName[1000], sn[1000];
64 snprintf(cn, sizeof(cn), "email %s", f); 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 }
65 printf("dn: cn=%s, %s\n", cn, ldap_base); 76 printf("dn: cn=%s, %s\n", cn, ldap_base);
66 printf("cn: %s\n", cn); 77 printf("cn: %s\n", cn);
67 printf("sn: %s\n", f); 78 printf("givenName: %s\n", givenName);
79 printf("sn: %s\n", sn);
68 printf("mail: %s\n", m); 80 printf("mail: %s\n", m);
69 printf("objectClass: %s\n\n", ldap_class); 81 printf("objectClass: %s\n\n", ldap_class);
70 } 82 }
71 } 83 }
72 } 84 }