From: Andre Date: Sat, 15 Apr 2006 17:40:41 +0000 (+0200) Subject: avoid struct ucred in audiod.c X-Git-Tag: v0.2.12~92 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=ff5444a95fa551c0bac1ca74f36770276a82703e;p=paraslash.git avoid struct ucred in audiod.c This is a preparation for making ucred optional. It moves everything which uses unix socket credentials into the single source file net.c. --- diff --git a/audiod.c b/audiod.c index f15ab710..b0f9f786 100644 --- a/audiod.c +++ b/audiod.c @@ -1417,14 +1417,14 @@ static int com_cycle(int fd, int argc, char **argv) return 1; } -static int check_perms(struct ucred *c) +static int check_perms(uid_t uid) { int i; if (!conf.user_allow_given) return 1; for (i = 0; i < conf.user_allow_given; i++) - if (c->uid == conf.user_allow_arg[i]) + if (uid == conf.user_allow_arg[i]) return 1; return -E_UCRED_PERM; } @@ -1432,7 +1432,6 @@ static int check_perms(struct ucred *c) static int handle_connect(void) { int i, argc, ret, clifd = -1; - struct ucred c; char *buf = para_malloc(MAXLINE), **argv = NULL; struct sockaddr_un unix_addr; @@ -1440,12 +1439,12 @@ static int handle_connect(void) if (ret < 0) goto out; clifd = ret; - ret = recv_cred_buffer(clifd, buf, MAXLINE - 1, &c); + ret = recv_cred_buffer(clifd, buf, MAXLINE - 1); if (ret < 0) goto out; - PARA_INFO_LOG("pid: %i, uid: %i, gid: %i, ret: %i, buf: %s\n", c.pid, c.uid, c.gid, ret, buf); + PARA_INFO_LOG("connection from user %i\n", ret); buf[ret] = '\0'; - ret = check_perms(&c); + ret = check_perms(ret); if (ret < 0) goto out; argc = split_args(buf, &argv, "\n"); diff --git a/net.c b/net.c index 599930aa..4d2f520f 100644 --- a/net.c +++ b/net.c @@ -392,10 +392,12 @@ static void dispose_fds(int *fds, int num) * \param size the size of \a buffer * \param cred the credentials are returned here * + * \return negative on errors, the user id on success. + * * \sa okir's Black Hats Manual * \sa recvmsg(2) */ -int recv_cred_buffer(int fd, char *buf, size_t size, struct ucred *cred) +int recv_cred_buffer(int fd, char *buf, size_t size) { char control[255]; struct msghdr msg; @@ -403,6 +405,7 @@ int recv_cred_buffer(int fd, char *buf, size_t size, struct ucred *cred) struct iovec iov; int result; int yes = 1; + struct ucred cred; setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &yes, sizeof(int)); memset(&msg, 0, sizeof(msg)); @@ -420,8 +423,8 @@ int recv_cred_buffer(int fd, char *buf, size_t size, struct ucred *cred) while (cmsg) { if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDENTIALS) { - memcpy(cred, CMSG_DATA(cmsg), sizeof(struct ucred)); - result = iov.iov_len; + memcpy(&cred, CMSG_DATA(cmsg), sizeof(struct ucred)); + result = cred.uid; } else if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { diff --git a/net.h b/net.h index 18f36c09..f2046664 100644 --- a/net.h +++ b/net.h @@ -40,7 +40,7 @@ int recv_bin_buffer(int, char *, ssize_t); int para_accept(int, void *addr, socklen_t size); int create_pf_socket(const char *, struct sockaddr_un *, int mod); int init_unix_addr(struct sockaddr_un *, const char *); -int recv_cred_buffer(int, char *, size_t, struct ucred *); +int recv_cred_buffer(int, char *, size_t); ssize_t send_cred_buffer(int, char*); int recv_pattern(int fd, const char *pattern, size_t bufsize); int init_tcp_socket(int port);