PR#3047: added Unix.setgroups, Unix.initgroups.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@9220 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
3c9c7b9949
commit
238cf4bde3
|
@ -0,0 +1,26 @@
|
|||
/***********************************************************************/
|
||||
/* */
|
||||
/* Objective Caml */
|
||||
/* */
|
||||
/* Copyright 2009 Institut National de Recherche en Informatique et */
|
||||
/* en Automatique. All rights reserved. This file is distributed */
|
||||
/* under the terms of the GNU Library General Public License, with */
|
||||
/* the special exception on linking described in file ../../LICENSE. */
|
||||
/* */
|
||||
/***********************************************************************/
|
||||
|
||||
/* Contributed by Stephane Glondu <steph@glondu.net> */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <limits.h>
|
||||
#include <grp.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
if (initgroups("root", 0) == -1 && errno != EPERM) return 1;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/***********************************************************************/
|
||||
/* */
|
||||
/* Objective Caml */
|
||||
/* */
|
||||
/* Copyright 2009 Institut National de Recherche en Informatique et */
|
||||
/* en Automatique. All rights reserved. This file is distributed */
|
||||
/* under the terms of the GNU Library General Public License, with */
|
||||
/* the special exception on linking described in file ../../LICENSE. */
|
||||
/* */
|
||||
/***********************************************************************/
|
||||
|
||||
/* Contributed by Stephane Glondu <steph@glondu.net> */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <limits.h>
|
||||
#include <grp.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
gid_t gidset[1];
|
||||
gidset[0] = 0;
|
||||
if (setgroups(1, gidset) == -1 && errno != EPERM) return 1;
|
||||
return 0;
|
||||
}
|
|
@ -144,6 +144,14 @@
|
|||
|
||||
/* Define HAS_GETGROUPS if you have getgroups(). */
|
||||
|
||||
#define HAS_SETGROUPS
|
||||
|
||||
/* Define HAS_SETGROUPS if you have setgroups(). */
|
||||
|
||||
#define HAS_INITGROUPS
|
||||
|
||||
/* Define HAS_INITGROUPS if you have initgroups(). */
|
||||
|
||||
#define HAS_TERMIOS
|
||||
|
||||
/* Define HAS_TERMIOS if you have /usr/include/termios.h and it is
|
||||
|
|
|
@ -983,6 +983,16 @@ if sh ./hasgot -i limits.h && sh ./runtest getgroups.c; then
|
|||
echo "#define HAS_GETGROUPS" >> s.h
|
||||
fi
|
||||
|
||||
if sh ./hasgot -i limits.h -i grp.h && sh ./runtest setgroups.c; then
|
||||
echo "setgroups() found."
|
||||
echo "#define HAS_SETGROUPS" >> s.h
|
||||
fi
|
||||
|
||||
if sh ./hasgot -i limits.h -i grp.h && sh ./runtest initgroups.c; then
|
||||
echo "initgroups() found."
|
||||
echo "#define HAS_INITGROUPS" >> s.h
|
||||
fi
|
||||
|
||||
if sh ./hasgot -i termios.h &&
|
||||
sh ./hasgot tcgetattr tcsetattr tcsendbreak tcflush tcflow; then
|
||||
echo "POSIX termios found."
|
||||
|
|
|
@ -473,6 +473,8 @@ external getgid : unit -> int = "unix_getgid"
|
|||
external getegid : unit -> int = "unix_getegid"
|
||||
external setgid : int -> unit = "unix_setgid"
|
||||
external getgroups : unit -> int array = "unix_getgroups"
|
||||
external setgroups : int array -> unit = "unix_setgroups"
|
||||
external initgroups : string -> int -> unit = "unix_initgroups"
|
||||
|
||||
type passwd_entry =
|
||||
{ pw_name : string;
|
||||
|
@ -1110,4 +1112,3 @@ let establish_server server_fun sockaddr =
|
|||
exit 0
|
||||
| id -> close s; ignore(waitpid [] id) (* Reclaim the son *)
|
||||
done
|
||||
|
||||
|
|
|
@ -26,11 +26,11 @@ COBJS=accept.o access.o addrofstr.o alarm.o bind.o chdir.o chmod.o \
|
|||
getaddrinfo.o getcwd.o getegid.o geteuid.o getgid.o \
|
||||
getgr.o getgroups.o gethost.o gethostname.o getlogin.o \
|
||||
getnameinfo.o getpeername.o getpid.o getppid.o getproto.o getpw.o \
|
||||
gettimeofday.o getserv.o getsockname.o getuid.o \
|
||||
gmtime.o isatty.o itimer.o kill.o link.o listen.o lockf.o lseek.o mkdir.o \
|
||||
mkfifo.o nice.o open.o opendir.o pipe.o putenv.o read.o \
|
||||
gettimeofday.o getserv.o getsockname.o getuid.o gmtime.o \
|
||||
initgroups.o isatty.o itimer.o kill.o link.o listen.o lockf.o lseek.o \
|
||||
mkdir.o mkfifo.o nice.o open.o opendir.o pipe.o putenv.o read.o \
|
||||
readdir.o readlink.o rename.o rewinddir.o rmdir.o select.o sendrecv.o \
|
||||
setgid.o setsid.o setuid.o shutdown.o signals.o \
|
||||
setgid.o setgroups.o setsid.o setuid.o shutdown.o signals.o \
|
||||
sleep.o socket.o socketaddr.o \
|
||||
socketpair.o sockopt.o stat.o strofaddr.o symlink.o termios.o \
|
||||
time.o times.o truncate.o umask.o unixsupport.o unlink.o \
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/***********************************************************************/
|
||||
/* */
|
||||
/* Objective Caml */
|
||||
/* */
|
||||
/* Copyright 2009 Institut National de Recherche en Informatique et */
|
||||
/* en Automatique. All rights reserved. This file is distributed */
|
||||
/* under the terms of the GNU Library General Public License, with */
|
||||
/* the special exception on linking described in file ../../LICENSE. */
|
||||
/* */
|
||||
/***********************************************************************/
|
||||
|
||||
/* Contributed by Stephane Glondu <steph@glondu.net> */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#include <mlvalues.h>
|
||||
#include <alloc.h>
|
||||
#include <fail.h>
|
||||
|
||||
#ifdef HAS_INITGROUPS
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifdef HAS_UNISTD
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <grp.h>
|
||||
#include "unixsupport.h"
|
||||
|
||||
CAMLprim value unix_initgroups(value user, value group)
|
||||
{
|
||||
if (initgroups(String_val(user), Int_val(group)) == -1) {
|
||||
uerror("setgroups", Nothing);
|
||||
}
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
CAMLprim value unix_initgroups(value user, value group)
|
||||
{ invalid_argument("initgroups not implemented"); }
|
||||
|
||||
#endif
|
|
@ -0,0 +1,53 @@
|
|||
/***********************************************************************/
|
||||
/* */
|
||||
/* Objective Caml */
|
||||
/* */
|
||||
/* Copyright 2009 Institut National de Recherche en Informatique et */
|
||||
/* en Automatique. All rights reserved. This file is distributed */
|
||||
/* under the terms of the GNU Library General Public License, with */
|
||||
/* the special exception on linking described in file ../../LICENSE. */
|
||||
/* */
|
||||
/***********************************************************************/
|
||||
|
||||
/* Contributed by Stephane Glondu <steph@glondu.net> */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#include <mlvalues.h>
|
||||
#include <alloc.h>
|
||||
#include <fail.h>
|
||||
#include <memory.h>
|
||||
|
||||
#ifdef HAS_SETGROUPS
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifdef HAS_UNISTD
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <grp.h>
|
||||
#include "unixsupport.h"
|
||||
|
||||
CAMLprim value unix_setgroups(value groups)
|
||||
{
|
||||
gid_t * gidset;
|
||||
mlsize_t size, i;
|
||||
int n;
|
||||
|
||||
size = Wosize_val(groups);
|
||||
gidset = (gid_t *) stat_alloc(size * sizeof(gid_t));
|
||||
for (i = 0; i < size; i++) gidset[i] = Int_val(Field(groups, i));
|
||||
|
||||
n = setgroups(size, gidset);
|
||||
|
||||
stat_free(gidset);
|
||||
if (n == -1) uerror("setgroups", Nothing);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
CAMLprim value unix_setgroups(value groups)
|
||||
{ invalid_argument("setgroups not implemented"); }
|
||||
|
||||
#endif
|
|
@ -365,6 +365,8 @@ external getgid : unit -> int = "unix_getgid"
|
|||
external getegid : unit -> int = "unix_getegid"
|
||||
external setgid : int -> unit = "unix_setgid"
|
||||
external getgroups : unit -> int array = "unix_getgroups"
|
||||
external setgroups : int array -> unit = "unix_setgroups"
|
||||
external initgroups : string -> int -> unit = "unix_initgroups"
|
||||
|
||||
type passwd_entry =
|
||||
{ pw_name : string;
|
||||
|
|
|
@ -820,6 +820,16 @@ val getgroups : unit -> int array
|
|||
(** Return the list of groups to which the user executing the process
|
||||
belongs. *)
|
||||
|
||||
val setgroups : int array -> unit
|
||||
(** [setgroups groups] sets the supplementary group IDs for the
|
||||
calling process. Appropriate privileges are required. *)
|
||||
|
||||
val initgroups : string -> int -> unit
|
||||
(** [initgroups user group] initializes the group access list by
|
||||
reading the group database /etc/group and using all groups of
|
||||
which [user] is a member. The additional group [group] is also
|
||||
added to the list. *)
|
||||
|
||||
type passwd_entry =
|
||||
{ pw_name : string;
|
||||
pw_passwd : string;
|
||||
|
|
|
@ -435,6 +435,8 @@ let getegid = getgid
|
|||
let setgid id = invalid_arg "Unix.setgid not implemented"
|
||||
|
||||
let getgroups () = [|1|]
|
||||
let setgroups _ = invalid_arg "Unix.setgroups not implemented"
|
||||
let initgroups _ _ = invalid_arg "Unix.initgroups not implemented"
|
||||
|
||||
type passwd_entry =
|
||||
{ pw_name : string;
|
||||
|
|
Loading…
Reference in New Issue