+/* This looks up a login name and returns the SMS internal ID. It is used
+ * by authenticate to put the users_id in the client structure.
+ */
+
+int get_users_id(name)
+char *name;
+##{
+## int id, rowcount;
+## char *login;
+
+ login = name;
+
+## range of u is users
+## repeat retrieve (id = u.#users_id) where u.#login = @login
+## inquire_equel (rowcount = "rowcount")
+
+ if (rowcount == 1)
+ return(id);
+ else
+ return(0);
+##}
+
+
+/* Turn a kerberos name into the user's ID of the account that principal
+ * owns. Sets the kerberos ID and user ID.
+ */
+
+set_krb_mapping(name, login, ok, kid, uid)
+char *name;
+char *login;
+int ok;
+int *kid;
+int *uid;
+##{
+## int u_id, k_id, rowcount;
+## char *krbname;
+
+ krbname = name;
+ *kid = 0;
+ *uid = 0;
+
+## range of k is krbmap
+## range of s is strings
+## repeat retrieve (u_id = k.#users_id, k_id = k.#string_id)
+## where k.string_id = s.string_id and s.string = @krbname
+## inquire_equel (rowcount = "rowcount")
+
+ if (rowcount == 1) {
+ *kid = -k_id;
+ *uid = u_id;
+ return;
+ }
+
+## repeat retrieve (k_id = s.#string_id) where s.string = @krbname
+## inquire_equel (rowcount = "rowcount")
+
+ if (rowcount == 1) {
+ *kid = -k_id;
+ }
+
+ if (!ok) {
+ *uid = *kid;
+ return;
+ }
+
+ *uid = get_users_id(login);
+ if (*kid == 0)
+ *kid = *uid;
+##}
+
+
+/* Cache the lists that the client is a member of. These will be used
+ * to speed up access checking later.
+ */
+
+set_client_lists(cl)
+client *cl;
+##{
+## int lid, mid;
+## char *type;
+ int count = 0;
+
+ cl->lists[count] = 0;
+ if (cl->users_id != 0) {
+ type = "USER";
+ mid = cl->users_id;
+ } else if (cl->client_id != 0) {
+ type = "KERBEROS";
+ mid = -cl->client_id;
+ } else
+ return;
+
+## range of m is members
+## repeat retrieve (lid = m.list_id) where m.member_type = @type and
+## m.member_id = @mid {
+ cl->lists[count++] = lid;
+ if (count >= NLISTS)
+## endretrieve
+## }
+ if (count >= NLISTS) {
+ cl->lists[0] = 0;
+ com_err(whoami, 0, "too many lists to cache");
+ } else
+ cl->lists[count] = 0;
+##}
+
+