/*
* Open the systrace device and return the fd or -1 on failure.
- * XXX - warn here on error or in caller?
*/
static int
systrace_open()
if (nread != sizeof(msg)) {
if (nread == -1 && (errno == EINTR || errno == EAGAIN))
continue;
- kill(pid, SIGKILL); /* XXX - kill all pids in list */
+ killall(&children, SIGKILL);
_exit(nread != 0); /* shouldn't happen */
}
handler = find_handler(msg.msg_pid, msg.msg_data.msg_ask.code);
if (handler != NULL) {
/*
- * handler is run twice, once before we answer and once
- * after. We only want to log attempts when our answer
- * is accepted; otherwise we can get dupes.
+ * The handler is run twice, once before we answer and
+ * once after. We only want to log attempts when our
+ * answer is accepted; otherwise we can get dupes.
*/
cookie = handler(fd, msg.msg_pid, &msg.msg_data.msg_ask, -1,
&ans.stra_policy, &ans.stra_error);
}
fail:
- kill(pid, SIGKILL); /* XXX - kill all pids in list */
+ killall(&children, SIGKILL);
_exit(1);
}
/*
* Read up to bufsiz bytes from addr into buf, stopping when we hit
* a NUL byte. Reads are done in chunks since STRIOCIO cannot
- * handle a strio_len > the actual kernel buffer.
- * XXX - could pass a hint for chunksiz
- * XXX - need to indicate oflow
+ * handle a strio_len > the actual kernel buffer. It might be nice
+ * to pass a starting chunksize though.
*/
static ssize_t
read_string(fd, pid, addr, buf, bufsiz)
}
}
*cp = '\0';
- return(cp - buf);
+ return(bufsiz >= chunksiz ? cp - buf : -1);
}
static schandler_t
}
if (off == (char *)askp->args[1])
continue; /* skip argv[0] */
- if ((len = read_string(fd, pid, ap, cp, ep - cp)) == -1) {
- warn("STRIOCIO");
+ if ((len = read_string(fd, pid, ap, cp, ep - cp)) == -1)
return(-1);
- }
cp += len;
*cp++ = ' '; /* replace NUL with a space */
}
}
return(validated);
}
+
+/*
+ * Kill all pids in the list
+ */
+static void
+killall(head, sig)
+ struct listhead *head;
+ int sig;
+{
+ struct childinfo *child;
+
+ for (child = head->first; child != NULL; child = child->next)
+ (void) kill(child->pid, sig);
+}
__P((int, pid_t, struct str_msg_ask *, int, int *, int *));
struct childinfo;
+struct listhead;
extern struct passwd *sudo_pwdup __P((const struct passwd *, int));
extern struct passwd *sudo_getpwuid __P((uid_t));
static void rm_child __P((pid_t));
static void update_child __P((pid_t, uid_t));
static struct childinfo *find_child __P((pid_t));
+static void killall __P((struct listhead *, int));
static struct listhead children; /* list of children being traced */
static int initialized; /* set to true when we are inited */