Date: Wed, 9 Aug 2006 18:45:02 GMT From: Michael Bushkov <bushman@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 103527 for review Message-ID: <200608091845.k79Ij2m8092930@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=103527 Change 103527 by bushman@bushman_nss_ldap_cached on 2006/08/09 18:44:06 Strings unescaping routine added, a bug in groups and in services fixed. Affected files ... .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_ldap/ldap_group.c#10 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_ldap/ldap_serv.c#8 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_ldap/ldapsearch.c#10 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_ldap/ldaputil.c#11 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_ldap/ldaputil.h#11 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_ldap/nss_ldap.c#11 edit Differences ... ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_ldap/ldap_group.c#10 (text+ko) ==== ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_ldap/ldap_serv.c#8 (text+ko) ==== @@ -248,10 +248,10 @@ if (proto != NULL) __nss_ldap_format_filter(fmt, NSS_LDAP_FILTER_ARGS_INT_STR, filter, - sizeof(filter), port, proto); + sizeof(filter), htons(port), proto); else __nss_ldap_format_filter(fmt, NSS_LDAP_FILTER_ARGS_INT_ANY, filter, - sizeof(filter), port); + sizeof(filter), htons(port)); memset(&mdata, 0, sizeof(struct services_mdata)); mdata.serv = serv; @@ -262,6 +262,7 @@ (void *)&mdata, buffer, bufsize, nss_ldap_parse_servent); + printf("== %d\n", rv); if (rv == NS_SUCCESS) *result = serv; @@ -288,7 +289,7 @@ rv = __nss_ldap_getent(NSS_LDAP_MAP_SERVICES, filter, (void *)&mdata, buffer, bufsize, nss_ldap_parse_servent, nss_ldap_destroy_servent); - + if (rv == NS_SUCCESS) *result = serv; ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_ldap/ldapsearch.c#10 (text+ko) ==== @@ -324,8 +324,8 @@ memcpy(buf, cstr, size + 1); *str = buf; *len = size + 1; - - return (NSS_LDAP_SUCCESS); + + return (__nss_ldap_unescape_string(buf, buf, size + 1)); } int ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_ldap/ldaputil.c#11 (text+ko) ==== @@ -91,6 +91,69 @@ } int +__nss_ldap_unescape_string(char const *str, char *buffer, size_t bufsize) +{ + char cmp_buf[3]; + char const *sp; + char *bp; + int prev_slash, slash_mod; + + cmp_buf[2] = '\0'; + prev_slash = 0; + slash_mod = 0; + sp = str; + bp = buffer; + do { + if (*sp == '\\') { + if (prev_slash == 0) { + prev_slash = 1; + slash_mod = 1; + } else { + if (slash_mod == 1) { + *bp = '\\'; + ++bp; + slash_mod = 0; + } else + slash_mod = 1; + } + } else if ((prev_slash == 1) && (*sp != '\0')) { + if (slash_mod == 1 ) { + cmp_buf[0] = *sp; + cmp_buf[1] = *(sp + 1); + if (strncasecmp(cmp_buf, "2a", 2) == 0) { + *bp = '*'; + } else if (strncasecmp(cmp_buf, "2b", 2) == 0) { + *bp = '+'; + } else if (strncasecmp(cmp_buf, "28", 2) == 0) { + *bp = '('; + } else if (strncasecmp(cmp_buf, "29", 2) == 0) { + *bp = ')'; + } else if (strncasecmp(cmp_buf, "5c", 2) == 0) { + *bp = '\\'; + } else + return (NSS_LDAP_PARSE_ERROR); + + ++bp; + + if (cmp_buf[1] != '\0') + ++sp; + else + *bp = '\0'; + } + + prev_slash = 0; + slash_mod = 0; + } else { + *bp = *sp; + ++bp; + } + + } while (*(sp++) != '\0'); + + return (NSS_LDAP_SUCCESS); +} + +int __nss_ldap_format_filter(char const *fmt, int type, char *buffer, size_t bufsize, ...) { ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_ldap/ldaputil.h#11 (text+ko) ==== @@ -39,6 +39,7 @@ #define NSS_LDAP_FILTER_ARGS_INT_ANY 7 extern int __nss_ldap_escape_string(char const *, char *, size_t); +extern int __nss_ldap_unescape_string(char const *, char *, size_t); extern int __nss_ldap_format_filter(char const *, int, char *, size_t, ...); #endif /* _LDAPUTILS_H_ */ ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_ldap/nss_ldap.c#11 (text+ko) ==== @@ -70,13 +70,13 @@ {NSDB_PASSWD_COMPAT, "setpwent", __ldap_setpwent, (void *)nss_set_ent}, {NSDB_GROUP, "getgrnam_r", __ldap_group, (void *)nss_lt_name}, - {NSDB_GROUP, "getgruid_r", __ldap_group, (void *)nss_lt_id}, + {NSDB_GROUP, "getgrgid_r", __ldap_group, (void *)nss_lt_id}, {NSDB_GROUP, "getgrent_r", __ldap_group, (void *)nss_lt_all}, {NSDB_GROUP, "endgrent", __ldap_setgrent, (void *)nss_end_ent}, {NSDB_GROUP, "setgrent", __ldap_setgrent, (void *)nss_set_ent}, {NSDB_GROUP_COMPAT, "getgrnam_r", __ldap_group, (void *)nss_lt_name}, - {NSDB_GROUP_COMPAT, "getgruid_r", __ldap_group, (void *)nss_lt_id}, + {NSDB_GROUP_COMPAT, "getgrgid_r", __ldap_group, (void *)nss_lt_id}, {NSDB_GROUP_COMPAT, "getgrent_r", __ldap_group, (void *)nss_lt_all}, {NSDB_GROUP_COMPAT, "endgrent", __ldap_setgrent, (void *)nss_end_ent}, {NSDB_GROUP_COMPAT, "setgrent", __ldap_setgrent, (void *)nss_set_ent},
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608091845.k79Ij2m8092930>