1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Services conforming to POSIX
19 #include <sys/types.h>
26 # Set the real current user id of this process
27 fun uid
=(uid
: Int): Bool `{ return setuid(uid); `}
29 # Current real user id of this process
30 fun uid: Int `{ return getuid(); `}
32 # Set the current real group id of this process
33 fun gid
=(gid
: Int): Bool `{ return setgid(gid); `}
35 # Current real group id of this process
36 fun gid: Int `{ return getgid(); `}
38 # Set the effective user id of this process
39 fun euid
=(uid
: Int): Bool `{ return seteuid(uid); `}
41 # The effective user id of this process
42 fun euid: Int `{ return geteuid(); `}
44 # Set the effective group id of this process
45 fun egid
=(gid
: Int): Bool `{ return setegid(gid); `}
47 # The effective group id of this process
48 fun egid: Int `{ return getegid(); `}
51 # Information on a user account
52 extern class Passwd `{struct passwd*`}
53 # Get the `Passwd` of the user with the `uid
`
54 new from_uid(uid: Int) `{ return getpwuid(uid); `}
56 # Get the `Passwd` of the user with the `name`
57 new from_name
(name
: String) import String.to_cstring
`{ return getpwnam( String_to_cstring(name) ); `}
60 fun name: String import CString.to_s `{ return CString_to_s(self->pw_name); `}
63 fun passwd
: String import CString.to_s
`{ return CString_to_s(self->pw_passwd); `}
66 fun uid: Int `{ return self->pw_uid; `}
69 fun gid
: Int `{ return self->pw_gid; `}
72 fun dir: String import CString.to_s `{ return CString_to_s(self->pw_dir); `}
75 fun shell
: String import CString.to_s
`{ return CString_to_s(self->pw_shell); `}
78 # Information on a user group
79 extern class Group `{struct group*`}
80 # Get a group from its id
81 new from_gid
(gid
: Int) `{ return getgrgid(gid); `}
83 # Get a group from its name
84 new from_name(name: String) import String.to_cstring `{ return getgrnam( String_to_cstring(name) ); `}
87 fun name
: String import CString.to_s
`{ return CString_to_s(self->gr_name); `}
89 # Encrypted password of this group
90 fun passwd: String import CString.to_s `{ return CString_to_s(self->gr_passwd); `}
93 fun gid
: Int `{ return self->gr_gid; `}
95 # List of the members of the group
96 fun mem: Array[String] import Array[String], Array[String].add, CString.to_s `{
102 ret
= new_Array_of_String
();
104 for (m
= 0; mem
[m
] != NULL; m
++)
105 Array_of_String_add(ret
, CString_to_s(mem
[m
]));