Recently I had to start diffing deeper in ypldap. The main problem I'm
trying to solve is that _some_ LDAP attributes are case-insensetive,
including _some_ that could be used as user names. Until I get all
the picture myself, I won't post all the boring details I came with.
But while browsing the ypldap code, I've come across some nits, which
I want to share. Here is the first one.
Those are cases RB_NFIND is exactly for, aren't them? Okay?
--
WBR,
Vadim Zhukov
Index: yp.c
===================================================================
RCS file: /cvs/src/usr.sbin/ypldap/yp.c,v
retrieving revision 1.18
diff -u -p -r1.18 yp.c
--- yp.c 29 Nov 2016 17:15:27 -0000 1.18
+++ yp.c 5 Dec 2017 10:09:45 -0000
@@ -490,25 +490,10 @@ ypproc_next_2_svc(ypreq_key *arg, struct
(void)strncpy(key, arg->key.keydat_val,
arg->key.keydat_len);
ukey.ue_line = key;
- if ((ue = RB_FIND(user_name_tree, env->sc_user_names,
+ if ((ue = RB_NFIND(user_name_tree, env->sc_user_names,
&ukey)) == NULL) {
- /*
- * canacar's trick:
- * the user might have been deleted in between calls
- * to next since the tree may be modified by a reload.
- * next should still return the next user in
- * lexicographical order, hence insert the search key
- * and look up the next field, then remove it again.
- */
- RB_INSERT(user_name_tree, env->sc_user_names, &ukey);
- if ((ue = RB_NEXT(user_name_tree, &env->sc_user_names,
- &ukey)) == NULL) {
- RB_REMOVE(user_name_tree, env->sc_user_names,
- &ukey);
- res.stat = YP_NOKEY;
- return (&res);
- }
- RB_REMOVE(user_name_tree, env->sc_user_names, &ukey);
+ res.stat = YP_NOKEY;
+ return (&res);
}
line = ue->ue_line + (strlen(ue->ue_line) + 1);
line = line + (strlen(line) + 1);
@@ -522,20 +507,10 @@ ypproc_next_2_svc(ypreq_key *arg, struct
arg->key.keydat_len);
gkey.ge_line = key;
- if ((ge = RB_FIND(group_name_tree, env->sc_group_names,
+ if ((ge = RB_NFIND(group_name_tree, env->sc_group_names,
&gkey)) == NULL) {
- /*
- * canacar's trick reloaded.
- */
- RB_INSERT(group_name_tree, env->sc_group_names, &gkey);
- if ((ge = RB_NEXT(group_name_tree, &env->sc_group_names,
- &gkey)) == NULL) {
- RB_REMOVE(group_name_tree, env->sc_group_names,
- &gkey);
- res.stat = YP_NOKEY;
- return (&res);
- }
- RB_REMOVE(group_name_tree, env->sc_group_names, &gkey);
+ res.stat = YP_NOKEY;
+ return (&res);
}
line = ge->ge_line + (strlen(ge->ge_line) + 1);