Skip to content

Commit

Permalink
On platforms with no way to get peer UID, use getuid(), also fix some…
Browse files Browse the repository at this point in the history
… failure

checks.
  • Loading branch information
nicm committed Apr 6, 2022
1 parent 3a6d82b commit 8bcd392
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd-queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ cmdq_add_message(struct cmdq_item *item)
tmp = cmd_print(item->cmd);
if (c != NULL) {
uid = proc_get_peer_uid(c->peer);
if (uid != getuid()) {
if (uid != (uid_t)-1 && uid != getuid()) {
if ((pw = getpwuid(uid)) != NULL)
xasprintf(&user, "[%s]", pw->pw_name);
else
Expand Down
3 changes: 1 addition & 2 deletions compat/getpeereid.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ getpeereid(int s, uid_t *uid, gid_t *gid)
return (0);
}
#else
errno = EOPNOTSUPP;
return (-1);
return (getuid());
#endif
}
8 changes: 6 additions & 2 deletions server-acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ server_acl_user_deny_write(uid_t uid)

TAILQ_FOREACH(c, &clients, entry) {
uid = proc_get_peer_uid(c->peer);
if (uid == user->uid && uid == user->uid)
if (uid != (uid_t)-1 && uid == user->uid)
c->flags |= CLIENT_READONLY;
}
}
Expand All @@ -164,7 +164,11 @@ int
server_acl_join(struct client *c)
{
struct server_acl_user *user;
uid_t uid = proc_get_peer_uid(c->peer);
uid_t uid;

uid = proc_get_peer_uid(c->peer);
if (uid == (uid_t)-1)
return (0);

user = server_acl_user_find(uid);
if (user == NULL)
Expand Down

0 comments on commit 8bcd392

Please sign in to comment.