summaryrefslogtreecommitdiffstats
path: root/normalize_dn.c
diff options
context:
space:
mode:
Diffstat (limited to 'normalize_dn.c')
-rw-r--r--normalize_dn.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/normalize_dn.c b/normalize_dn.c
new file mode 100644
index 0000000..0cdf47e
--- /dev/null
+++ b/normalize_dn.c
@@ -0,0 +1,26 @@
+#include <stddef.h>
+#include <ctype.h>
+
+/* "ou=fnord; O=fefe; c=de" -> "ou=fnord,o=fefe,c=de" */
+/* returns the length of the new string */
+size_t normalize_dn(char* dest,const char* src,int len) {
+ int makelower=1;
+ char* orig=dest;
+ while (len) {
+ if (*src==';' || *src==',') {
+ *dest=',';
+ while (len>1 && src[1]==' ') { ++src; --len; }
+ makelower=1;
+ } else {
+ if (makelower)
+ *dest=tolower(*src);
+ else
+ *dest=*src;
+ if (*dest=='=') makelower=0;
+ }
+ ++dest;
+ ++src;
+ --len;
+ }
+ return dest-orig;
+}