1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2013 Alexis Laferrière <alexis.laf@xymus.net>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Services conforming to POSIX
23 #include <sys/types.h>
30 # Set the real current user id of this process
31 fun uid
=(uid
: Int): Bool `{ return setuid(uid); `}
33 # Current real user id of this process
34 fun uid: Int `{ return getuid(); `}
36 # Set the current real group id of this process
37 fun gid
=(gid
: Int): Bool `{ return setgid(gid); `}
39 # Current real group id of this process
40 fun gid: Int `{ return getgid(); `}
42 # Set the effective user id of this process
43 fun euid
=(uid
: Int): Bool `{ return seteuid(uid); `}
45 # The effective user id of this process
46 fun euid: Int `{ return geteuid(); `}
48 # Set the effective group id of this process
49 fun egid
=(gid
: Int): Bool `{ return setegid(gid); `}
51 # The effective group id of this process
52 fun egid: Int `{ return getegid(); `}
55 # Information on a user account
56 extern class Passwd `{struct passwd*`}
57 # Get the `Passwd` of the user with the `uid
`
58 new from_uid(uid: Int) `{ return getpwuid(uid); `}
60 # Get the `Passwd` of the user with the `name`
61 new from_name
(name
: String) import String.to_cstring
`{ return getpwnam( String_to_cstring(name) ); `}
64 fun name: String import CString.to_s `{ return CString_to_s(self->pw_name); `}
67 fun passwd
: String import CString.to_s
`{ return CString_to_s(self->pw_passwd); `}
70 fun uid: Int `{ return self->pw_uid; `}
73 fun gid
: Int `{ return self->pw_gid; `}
76 fun dir: String import CString.to_s `{ return CString_to_s(self->pw_dir); `}
79 fun shell
: String import CString.to_s
`{ return CString_to_s(self->pw_shell); `}
82 # Information on a user group
83 extern class Group `{struct group*`}
84 # Get a group from its id
85 new from_gid
(gid
: Int) `{ return getgrgid(gid); `}
87 # Get a group from its name
88 new from_name(name: String) import String.to_cstring `{ return getgrnam( String_to_cstring(name) ); `}
91 fun name
: String import CString.to_s
`{ return CString_to_s(self->gr_name); `}
93 # Encrypted password of this group
94 fun passwd: String import CString.to_s `{ return CString_to_s(self->gr_passwd); `}
97 fun gid
: Int `{ return self->gr_gid; `}
99 # List of the members of the group
100 fun mem: Array[String] import Array[String], Array[String].add, CString.to_s `{
106 ret
= new_Array_of_String
();
108 for (m
= 0; mem
[m
] != NULL; m
++)
109 Array_of_String_add(ret
, CString_to_s(mem
[m
]));