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 fun uid
=(uid
: Int): Bool `{ return setuid(uid); `}
31 fun uid: Int `{ return getuid(); `}
33 fun gid
=(gid
: Int): Bool `{ return setgid(gid); `}
34 fun gid: Int `{ return getgid(); `}
36 fun euid
=(uid
: Int): Bool `{ return seteuid(uid); `}
37 fun euid: Int `{ return geteuid(); `}
39 fun egid
=(gid
: Int): Bool `{ return setegid(gid); `}
40 fun egid: Int `{ return getegid(); `}
43 extern class Passwd `{struct passwd*`}
44 new from_uid(uid: Int) `{ return getpwuid(uid); `}
45 new from_name
(name
: String) import String.to_cstring
`{ return getpwnam( String_to_cstring(name) ); `}
47 fun name: String import NativeString.to_s `{ return NativeString_to_s(recv->pw_name); `}
48 fun passwd
: String import NativeString.to_s
`{ return NativeString_to_s(recv->pw_passwd); `}
49 fun uid: Int `{ return recv->pw_uid; `}
50 fun gid
: Int `{ return recv->pw_gid; `}
51 fun gecos: String import NativeString.to_s `{ return NativeString_to_s(recv->pw_gecos); `}
52 fun dir
: String import NativeString.to_s
`{ return NativeString_to_s(recv->pw_dir); `}
53 fun shell: String import NativeString.to_s `{ return NativeString_to_s(recv->pw_shell); `}
56 extern class Group `{struct group*`}
57 new from_gid(gid: Int) `{ return getgrgid(gid); `}
58 new from_name
(name
: String) import String.to_cstring
`{ return getgrnam( String_to_cstring(name) ); `}
60 fun name: String import NativeString.to_s `{ return NativeString_to_s(recv->gr_name); `}
61 fun passwd
: String import NativeString.to_s
`{ return NativeString_to_s(recv->gr_passwd); `}
62 fun gid: Int `{ return recv->gr_gid; `}
63 fun mem
: Array[String] import Array[String], Array[String].add
, NativeString.to_s
`{
69 ret = new_Array_of_String();
71 for (m = 0; mem[m] != NULL; m++)
72 Array_of_String_add(ret, NativeString_to_s(mem[m]));