Add chown(3).
This commit is contained in:
parent
a11439bc87
commit
2389a834b5
|
@ -116,6 +116,7 @@ HOSTEDOBJS=\
|
||||||
access.o \
|
access.o \
|
||||||
chdir.o \
|
chdir.o \
|
||||||
chmod.o \
|
chmod.o \
|
||||||
|
chown.o \
|
||||||
clock.o \
|
clock.o \
|
||||||
close.o \
|
close.o \
|
||||||
$(CPUDIR)/fork.o \
|
$(CPUDIR)/fork.o \
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
chown.cpp
|
||||||
|
Changes the owner and group of a file.
|
||||||
|
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
|
@ -88,7 +88,6 @@ extern char** environ;
|
||||||
/* TODO: These are not implemented in sortix libc yet. */
|
/* TODO: These are not implemented in sortix libc yet. */
|
||||||
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
||||||
unsigned alarm(unsigned);
|
unsigned alarm(unsigned);
|
||||||
int chown(const char*, uid_t, gid_t);
|
|
||||||
size_t confstr(int, char*, size_t);
|
size_t confstr(int, char*, size_t);
|
||||||
char* crypt(const char*, const char*);
|
char* crypt(const char*, const char*);
|
||||||
char* ctermid(char*);
|
char* ctermid(char*);
|
||||||
|
@ -153,6 +152,7 @@ extern int opterr, optind, optopt;
|
||||||
|
|
||||||
int access(const char*, int);
|
int access(const char*, int);
|
||||||
int chdir(const char*);
|
int chdir(const char*);
|
||||||
|
int chown(const char*, uid_t, gid_t);
|
||||||
int close(int);
|
int close(int);
|
||||||
int dup(int);
|
int dup(int);
|
||||||
void _exit(int) __attribute__ ((noreturn));
|
void _exit(int) __attribute__ ((noreturn));
|
||||||
|
|
|
@ -79,6 +79,7 @@
|
||||||
#define SYSCALL_DISPMSG_ISSUE 55
|
#define SYSCALL_DISPMSG_ISSUE 55
|
||||||
#define SYSCALL_FSTATAT 56
|
#define SYSCALL_FSTATAT 56
|
||||||
#define SYSCALL_CHMOD 57
|
#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
|
#endif
|
||||||
|
|
|
@ -317,6 +317,22 @@ static int sys_chdir(const char* path)
|
||||||
return 0;
|
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<Descriptor> from = PrepareLookup(&relpath);
|
||||||
|
Ref<Descriptor> 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)
|
static int sys_chmod(const char* path, mode_t mode)
|
||||||
{
|
{
|
||||||
char* pathcopy = GetStringFromUser(path);
|
char* pathcopy = GetStringFromUser(path);
|
||||||
|
@ -374,6 +390,7 @@ void Init()
|
||||||
Syscall::Register(SYSCALL_ACCESS, (void*) sys_access);
|
Syscall::Register(SYSCALL_ACCESS, (void*) sys_access);
|
||||||
Syscall::Register(SYSCALL_CHDIR, (void*) sys_chdir);
|
Syscall::Register(SYSCALL_CHDIR, (void*) sys_chdir);
|
||||||
Syscall::Register(SYSCALL_CHMOD, (void*) sys_chmod);
|
Syscall::Register(SYSCALL_CHMOD, (void*) sys_chmod);
|
||||||
|
Syscall::Register(SYSCALL_CHOWN, (void*) sys_chown);
|
||||||
Syscall::Register(SYSCALL_CLOSE, (void*) sys_close);
|
Syscall::Register(SYSCALL_CLOSE, (void*) sys_close);
|
||||||
Syscall::Register(SYSCALL_DUP, (void*) sys_dup);
|
Syscall::Register(SYSCALL_DUP, (void*) sys_dup);
|
||||||
Syscall::Register(SYSCALL_FCNTL, (void*) sys_fcntl);
|
Syscall::Register(SYSCALL_FCNTL, (void*) sys_fcntl);
|
||||||
|
|
Loading…
Reference in New Issue