diff 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
line wrap: on
line diff
--- a/src/nick2ldif.cpp	Fri Dec 24 19:26:05 2010 -0800
+++ b/src/nick2ldif.cpp	Sat Apr 16 10:09:28 2011 -0700
@@ -18,7 +18,7 @@
 
 using namespace std;
 
-int main(int argc, const char** argv) {
+int main(int argc, char* const* argv) {
 	char c;
 	char *temp;
 	while ((c = getopt(argc, argv, "b:c:"))!= -1) {
@@ -46,6 +46,7 @@
 		cin.getline(line, LINE_SIZE);
 		int n = strlen(line);
 		if (!n) continue;
+        if (strncmp(line, "alias", 5) != 0) continue;   // not alias
 		char *f = line + 6; 	// skip alias keyword
 		char *e;
 		if (*f == '"') {
@@ -60,11 +61,22 @@
 		char *m = e+1;
 		while (*m == ' ') m++;
 		if (*m != '\0') {
-			char cn[1000];
-			snprintf(cn, sizeof(cn), "email %s", f);
+			char cn[1000], givenName[1000], sn[1000];
+			snprintf(cn, sizeof(cn), "%s", f);
+            char *ff = strchr(f, ' ');
+            if (ff) {
+                strncpy(givenName, ff+1, sizeof(givenName)-1);
+                *ff = '\0';
+                strncpy(sn, f, sizeof(sn)-1);
+            }
+            else {
+                strcpy(givenName, cn);
+                strcpy(sn, cn);
+            }
 			printf("dn: cn=%s, %s\n", cn, ldap_base);
 			printf("cn: %s\n", cn);
-			printf("sn: %s\n", f);
+            printf("givenName: %s\n", givenName);
+			printf("sn: %s\n", sn);
 			printf("mail: %s\n", m);
 			printf("objectClass: %s\n\n", ldap_class);
 		}