return(MR_PERM);
}
+
+/* access_host - successful if owner of host, or subnet containing host
+ */
+
+int host_access_level = 0;
+
+access_host(q, argv, cl)
+ struct query *q;
+ char *argv[];
+ client *cl;
+{
+ EXEC SQL BEGIN DECLARE SECTION;
+ int mid, sid, users_id, id;
+ char mtype[9], stype[9], *name;
+ EXEC SQL END DECLARE SECTION;
+ int status, client_id;
+ char *client_type;
+
+ if (q->type == APPEND) {
+ id = *(int *)argv[8];
+ EXEC SQL SELECT s.owner_type, s.owner_id
+ INTO :stype, :sid FROM subnet s
+ WHERE s.snet_id=:id;
+ mid =0;
+ } else if (q->type == RETRIEVE) {
+ name = argv[0];
+ EXEC SQL SELECT m.owner_type, m.owner_id, s.owner_type, s.owner_id
+ INTO :mtype, :mid, :stype, :sid FROM machine m, subnet s
+ WHERE m.name=:name and s.snet_id=m.snet_id;
+ } else {
+ id = *(int *)argv[0];
+ EXEC SQL SELECT m.owner_type, m.owner_id, s.owner_type, s.owner_id
+ INTO :mtype, :mid, :stype, :sid FROM machine m, subnet s
+ WHERE m.mach_id=:id and s.snet_id=m.snet_id;
+ }
+ if (sqlca.sqlerrd[2] != 1)
+ return(MR_PERM);
+
+ if ((status = get_client(cl, &client_type, &client_id)) != MR_SUCCESS)
+ return(status);
+ status = find_member(stype, sid, client_type, client_id, 0);
+ if (status) {
+ host_access_level = 1;
+ return(MR_SUCCESS);
+ }
+ status = find_member(mtype, mid, client_type, client_id, 0);
+ if (status) {
+ host_access_level = 2;
+ return(MR_SUCCESS);
+ } else
+ return(MR_PERM);
+}
+
+
+/* access_ahal - check for adding a host alias.
+ * successful if host has less then 2 aliases and (client is owner of
+ * host or subnet).
+ * If deleting an alias, any owner will do.
+ */
+
+access_ahal(q, argv, cl)
+ struct query *q;
+ char *argv[];
+ client *cl;
+{
+ EXEC SQL BEGIN DECLARE SECTION;
+ int cnt, id, mid, sid;
+ char mtype[256], stype[256];
+ EXEC SQL END DECLARE SECTION;
+ char *client_type;
+ int status, client_id;
+
+ id = *(int *)argv[1];
+
+ EXEC SQL SELECT count(name) INTO :cnt from hostalias WHERE mach_id = :id;
+ if (ingres_errno) return(mr_errcode);
+ /* if the type is APPEND, this is ahal and we need to make sure there
+ * will be no more than 2 aliases. If it's not, it must be dhal and
+ * any owner will do.
+ */
+ if (q->type == APPEND && cnt >= 2)
+ return(MR_PERM);
+
+ EXEC SQL SELECT m.owner_type, m.owner_id, s.owner_type, s.owner_id
+ INTO :mtype, :mid, :stype, :sid FROM machine m, subnet s
+ WHERE m.mach_id=:id and s.snet_id=m.snet_id;
+ if ((status = get_client(cl, &client_type, &client_id)) != MR_SUCCESS)
+ return(status);
+ status = find_member(mtype, mid, client_type, client_id, 0);
+ if (status)
+ return(MR_SUCCESS);
+ status = find_member(stype, sid, client_type, client_id, 0);
+ if (status)
+ return(MR_SUCCESS);
+ else
+ return(MR_PERM);
+}