nwrap: Add string manipulation functions.
authorRobin Hack <hack.robin@gmail.com>
Tue, 24 Mar 2015 14:14:35 +0000 (15:14 +0100)
committerMichael Adam <obnox@samba.org>
Wed, 7 Oct 2015 13:58:32 +0000 (15:58 +0200)
Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
src/nss_wrapper.c

index 74aa8c3dfb4a2715feed770af121f2acb2685615..2c2cbd653948a1a4e19dbc3c12c6ac405edb57dc 100644 (file)
@@ -939,6 +939,37 @@ static int libc_getpwuid_r(uid_t uid,
 }
 #endif
 
+static inline void str_tolower(char *dst, char *src)
+{
+       register char *src_tmp = src;
+       register char *dst_tmp = dst;
+
+       while (*src_tmp != '\0') {
+               *dst_tmp = tolower(*src_tmp);
+               ++src_tmp;
+               ++dst_tmp;
+       }
+}
+
+static bool str_tolower_copy(char **dst_name, const char *const src_name)
+{
+       char *h_name_lower;
+
+       if ((dst_name == NULL) || (src_name == NULL)) {
+               return false;
+       }
+
+       h_name_lower = strdup(src_name);
+       if (h_name_lower == NULL) {
+               NWRAP_LOG(NWRAP_LOG_DEBUG, "Out of memory while strdup");
+               return false;
+       }
+
+       str_tolower(h_name_lower, h_name_lower);
+       *dst_name = h_name_lower;
+       return true;
+}
+
 static void libc_setpwent(void)
 {
        nwrap_load_lib_function(NWRAP_LIBC, setpwent);