diff --git a/libc/Makefile b/libc/Makefile index 5a0df496..fb1616a5 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -116,6 +116,7 @@ HOSTEDOBJS=\ access.o \ chdir.o \ chmod.o \ +chown.o \ clock.o \ close.o \ $(CPUDIR)/fork.o \ diff --git a/libc/chown.cpp b/libc/chown.cpp new file mode 100644 index 00000000..399d6131 --- /dev/null +++ b/libc/chown.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2012. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + chown.cpp + Changes the owner and group of a file. + +*******************************************************************************/ + +#include +#include +#include + +DEFN_SYSCALL3(int, sys_chown, SYSCALL_CHOWN, const char*, uid_t, gid_t); + +extern "C" int chown(const char* path, uid_t owner, gid_t group) +{ + return sys_chown(path, owner, group); +} diff --git a/libc/include/unistd.h b/libc/include/unistd.h index 62f9c55e..3fdb5765 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -88,7 +88,6 @@ extern char** environ; /* TODO: These are not implemented in sortix libc yet. */ #if defined(__SORTIX_SHOW_UNIMPLEMENTED) unsigned alarm(unsigned); -int chown(const char*, uid_t, gid_t); size_t confstr(int, char*, size_t); char* crypt(const char*, const char*); char* ctermid(char*); @@ -153,6 +152,7 @@ extern int opterr, optind, optopt; int access(const char*, int); int chdir(const char*); +int chown(const char*, uid_t, gid_t); int close(int); int dup(int); void _exit(int) __attribute__ ((noreturn)); diff --git a/sortix/include/sortix/syscallnum.h b/sortix/include/sortix/syscallnum.h index 827054c4..c6310f05 100644 --- a/sortix/include/sortix/syscallnum.h +++ b/sortix/include/sortix/syscallnum.h @@ -79,6 +79,7 @@ #define SYSCALL_DISPMSG_ISSUE 55 #define SYSCALL_FSTATAT 56 #define SYSCALL_CHMOD 57 -#define SYSCALL_MAX_NUM 58 /* index of highest constant + 1 */ +#define SYSCALL_CHOWN 58 +#define SYSCALL_MAX_NUM 59 /* index of highest constant + 1 */ #endif diff --git a/sortix/io.cpp b/sortix/io.cpp index d0611da2..0fd4e277 100644 --- a/sortix/io.cpp +++ b/sortix/io.cpp @@ -317,6 +317,22 @@ static int sys_chdir(const char* path) return 0; } +static int sys_chown(const char* path, uid_t owner, gid_t group) +{ + char* pathcopy = GetStringFromUser(path); + if ( !pathcopy ) + return -1; + ioctx_t ctx; SetupUserIOCtx(&ctx); + const char* relpath = pathcopy; + Ref from = PrepareLookup(&relpath); + Ref desc = from->open(&ctx, relpath, O_WRONLY); + from.Reset(); + delete[] pathcopy; + if ( !desc ) + return -1; + return desc->chown(&ctx, owner, group); +} + static int sys_chmod(const char* path, mode_t mode) { char* pathcopy = GetStringFromUser(path); @@ -374,6 +390,7 @@ void Init() Syscall::Register(SYSCALL_ACCESS, (void*) sys_access); Syscall::Register(SYSCALL_CHDIR, (void*) sys_chdir); Syscall::Register(SYSCALL_CHMOD, (void*) sys_chmod); + Syscall::Register(SYSCALL_CHOWN, (void*) sys_chown); Syscall::Register(SYSCALL_CLOSE, (void*) sys_close); Syscall::Register(SYSCALL_DUP, (void*) sys_dup); Syscall::Register(SYSCALL_FCNTL, (void*) sys_fcntl);