1 diff --git a/CHANGELOG b/CHANGELOG
2 index fcfbe62..c29d577 100644
6 - improve handling of server not available.
7 - fix LDAP_URI server selection.
8 - add authentication option for using an external credential cache.
9 +- expand support for the "%" hack.
11 18/06/2007 autofs-5.0.2
12 -----------------------
13 diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
14 index 13fbff7..65f1fda 100644
15 --- a/modules/lookup_ldap.c
16 +++ b/modules/lookup_ldap.c
17 @@ -1411,6 +1411,140 @@ next:
18 return NSS_STATUS_SUCCESS;
22 + * Deal with encode and decode of % hack.
24 + * 0 => % hack not present.
25 + * -1 => syntax error or alloc fail.
26 + * 1 transofrmed value returned.
28 +static int decode_percent_hack(const char *name, char **key)
39 + while (*tmp && *tmp != '%' && *tmp != '[' && *tmp != ']')
53 + while (*tmp && *tmp != ']') {
64 + new = malloc(strlen(name) + 1);
71 + if (*tmp == '%' || *tmp == '[' || *tmp == ']') {
73 + if (*tmp && *tmp != '%')
85 +static int encode_percent_hack(const char *name, char **key, unsigned int use_class)
88 + unsigned int len = 0;
100 + else if (isupper(*tmp)) {
106 + if (*tmp && isupper(*tmp))
110 + while (*tmp && isupper(*tmp)) {
120 + if (len == strlen(name))
123 + new = malloc(len + 1);
132 + else if (isupper(*tmp)) {
133 + char next = *tmp++;
135 + if (*tmp && (!isupper(*tmp) || !use_class))
140 + while (*tmp && isupper(*tmp))
152 + return strlen(new);
155 static int read_one_map(struct autofs_point *ap,
156 struct lookup_context *ctxt,
157 time_t age, int *result_ldap)
158 @@ -1518,7 +1652,7 @@ static int read_one_map(struct autofs_point *ap,
159 * people using older schemas that allow '*' as a key
160 * value. Another case where there can be multiple key
161 * values is when people have used the "%" hack to specify
162 - * case matching ctriteria in a caase insensitive attribute.
163 + * case matching ctriteria in a case insensitive attribute.
165 count = ldap_count_values_len(bvKey);
167 @@ -1647,9 +1781,30 @@ static int read_one_map(struct autofs_point *ap,
171 - s_key = sanitize_path(k_val, k_len, ap->type, ap->logopt);
174 + if (strcasecmp(class, "nisObject")) {
175 + s_key = sanitize_path(k_val, k_len, ap->type, ap->logopt);
180 + int dec_len = decode_percent_hack(k_val, &dec_key);
184 + "could not use percent hack to decode key %s",
190 + s_key = sanitize_path(k_val, k_len, ap->type, ap->logopt);
192 + s_key = sanitize_path(dec_key, dec_len, ap->type, ap->logopt);
200 cache_update(mc, source, s_key, mapent, age);
201 @@ -1712,6 +1867,8 @@ static int lookup_one(struct autofs_point *ap,
203 LDAPMessage *result, *e;
204 char *class, *info, *entry;
205 + char *enc_key1, *enc_key2;
206 + int enc_len1 = 0, enc_len2 = 0;
207 struct berval **bvKey;
208 struct berval **bvValues;
210 @@ -1742,14 +1899,38 @@ static int lookup_one(struct autofs_point *ap,
212 if (*qKey == '*' && qKey_len == 1)
214 + else if (!strcasecmp(class, "nisObject")) {
215 + enc_len1 = encode_percent_hack(qKey, &enc_key1, 0);
216 + if (enc_len1 < 0) {
218 + "could not use percent hack encode key %s",
222 + if (enc_len1 != 0) {
223 + enc_len2 = encode_percent_hack(qKey, &enc_key2, 1);
224 + if (enc_len2 < 0) {
226 + "could not use percent hack encode key %s",
233 /* Build a query string. */
234 l = strlen(class) + 3*strlen(entry) + strlen(qKey) + 35;
236 + l += 2*strlen(entry) + enc_len1 + enc_len2 + 6;
240 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
241 crit(ap->logopt, MODPREFIX "malloc: %s", estr);
249 @@ -1757,8 +1938,27 @@ static int lookup_one(struct autofs_point *ap,
250 * Look for an entry in class under ctxt-base
251 * whose entry is equal to qKey.
253 - ql = sprintf(query,
254 - "(&(objectclass=%s)(|(%s=%s)(%s=/)(%s=\\2A)))", class, entry, qKey, entry, entry);
256 + ql = sprintf(query,
257 + "(&(objectclass=%s)(|(%s=%s)(%s=/)(%s=\\2A)))",
258 + class, entry, qKey, entry, entry);
261 + ql = sprintf(query,
262 + "(&(objectclass=%s)"
263 + "(|(%s=%s)(%s=%s)(%s=%s)(%s=/)(%s=\\2A)))",
264 + class, entry, qKey,
265 + entry, enc_key1, entry, enc_key2, entry, entry);
269 + ql = sprintf(query,
270 + "(&(objectclass=%s)"
271 + "(|(%s=%s)(%s=%s)(%s=/)(%s=\\2A)))",
272 + class, entry, qKey, entry, enc_key1, entry, entry);
278 MODPREFIX "error forming query string");
279 @@ -1934,9 +2134,30 @@ static int lookup_one(struct autofs_point *ap,
283 - s_key = sanitize_path(k_val, k_len, ap->type, ap->logopt);
286 + if (strcasecmp(class, "nisObject")) {
287 + s_key = sanitize_path(k_val, k_len, ap->type, ap->logopt);
292 + int dec_len = decode_percent_hack(k_val, &dec_key);
296 + "could not use percent hack to decode key %s",
302 + s_key = sanitize_path(k_val, k_len, ap->type, ap->logopt);
304 + s_key = sanitize_path(dec_key, dec_len, ap->type, ap->logopt);
312 ret = cache_update(mc, source, s_key, mapent, age);