Re: Proposal to automatically make the owner/user of an accepted socket the current process
[email protected] (Christos Zoulas) Fri, 6 Jun 2025 11:51:22 -0000 (UTC)
| Newsgroups | gmane.os.netbsd.devel.network,gmane.os.netbsd.devel.kernel |
|---|---|
| Message-ID | <[email protected]> |
In article <[email protected]>, Jason Thorpe <[email protected]> wrote: > > >> On Jun 5, 2025, at 7:51 PM, Emmanuel Nyarko <[email protected]> wrote: >> >> And also, fchown, no support for it yet ? > >fchown()? It changes the uid/gid of a file on disk, like chown() but >takes a file descriptor rather than a path. Try this on linux as root. sockets contain so_cred so presumably adding fchown to fileops will let you do that. FreeBSD already has fchown on their fileops, but they make it return EINVAL for sockets. christos #include <sys/socket.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <err.h> int main(void) { struct stat st; int s = socket(PF_INET, SOCK_STREAM, 0); if (s == -1) err(EXIT_FAILURE, "socket"); if (fstat(s, &st) == -1) err(EXIT_FAILURE, "fstat"); printf("uid=%d gid=%d\n", st.st_uid, st.st_gid); if (fchown(s, 100, 100) == -1) err(EXIT_FAILURE, "fchown"); if (fstat(s, &st) == -1) err(EXIT_FAILURE, "fstat"); printf("uid=%d gid=%d\n", st.st_uid, st.st_gid); return 0; }