Services conforming to POSIX

Introduced classes

extern class Group

posix :: Group

Information on a user group
extern class Passwd

posix :: Passwd

Information on a user account

Redefined classes

redef class Sys

posix :: posix $ Sys

The main class of the program.

All class definitions

extern class Group

posix $ Group

Information on a user group
extern class Passwd

posix $ Passwd

Information on a user account
redef class Sys

posix :: posix $ Sys

The main class of the program.
package_diagram posix::posix posix core core posix::posix->core privileges::privileges privileges privileges::privileges->posix::posix posix::ext ext posix::ext->posix::posix nitcorn::simple_file_server simple_file_server nitcorn::simple_file_server->privileges::privileges privileges::drop_privileges drop_privileges privileges::drop_privileges->privileges::privileges nitcorn::simple_file_server... ... nitcorn::simple_file_server...->nitcorn::simple_file_server privileges::drop_privileges... ... privileges::drop_privileges...->privileges::drop_privileges a_star-m a_star-m a_star-m->posix::ext a_star-m... ... a_star-m...->a_star-m

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module list

core :: list

This module handle double linked lists
module math

core :: math

Mathematical operations
module native

core :: native

Native structures for text and bytes
module numeric

core :: numeric

Advanced services for Numeric types
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O

Parents

module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.

Children

module ext

posix :: ext

Services not defined in POSIX but provided by most implementations
module privileges

privileges :: privileges

Process privileges management utilities

Descendants

module a_star-m

a_star-m

module drop_privileges

privileges :: drop_privileges

Example using the privileges module to drop privileges from root
module simple_file_server

nitcorn :: simple_file_server

Basic file server on port 80 by default, may require root to execute
# Services conforming to POSIX
module posix

in "C Header" `{
#include <sys/types.h>
#include <unistd.h>
#include <pwd.h>
#include <grp.h>
`}

redef class Sys
	# Set the real current user id of this process
	fun uid=(uid: Int): Bool `{ return setuid(uid); `}

	# Current real user id of this process
	fun uid: Int `{ return getuid(); `}

	# Set the current real group id of this process
	fun gid=(gid: Int): Bool `{ return setgid(gid); `}

	# Current real group id of this process
	fun gid: Int `{ return getgid(); `}

	# Set the effective user id of this process
	fun euid=(uid: Int): Bool `{ return seteuid(uid); `}

	# The effective user id of this process
	fun euid: Int `{ return geteuid(); `}

	# Set the effective group id of this process
	fun egid=(gid: Int): Bool `{ return setegid(gid); `}

	# The effective group id of this process
	fun egid: Int `{ return getegid(); `}
end

# Information on a user account
extern class Passwd `{struct passwd*`}
	# Get the `Passwd` of the user with the `uid`
	new from_uid(uid: Int) `{ return getpwuid(uid); `}

	# Get the `Passwd` of the user with the `name`
	new from_name(name: String) import String.to_cstring `{ return getpwnam( String_to_cstring(name) ); `}

	# Username
	fun name: String import CString.to_s `{ return CString_to_s(self->pw_name); `}

	# User password
	fun passwd: String import CString.to_s `{ return CString_to_s(self->pw_passwd); `}

	# User ID
	fun uid: Int `{ return self->pw_uid; `}

	# Group ID
	fun gid: Int `{ return self->pw_gid; `}

	# Home directory
	fun dir: String import CString.to_s `{ return CString_to_s(self->pw_dir); `}

	# Shell program
	fun shell: String import CString.to_s `{ return CString_to_s(self->pw_shell); `}
end

# Information on a user group
extern class Group `{struct group*`}
	# Get a group from its id
	new from_gid(gid: Int) `{ return getgrgid(gid); `}

	# Get a group from its name
	new from_name(name: String) import String.to_cstring `{ return getgrnam( String_to_cstring(name) ); `}

	# Name of this ground
	fun name: String import CString.to_s `{ return CString_to_s(self->gr_name); `}

	# Encrypted password of this group
	fun passwd: String import CString.to_s `{ return CString_to_s(self->gr_passwd); `}

	# Id of this group
	fun gid: Int `{ return self->gr_gid; `}

	# List of the members of the group
	fun mem: Array[String] import Array[String], Array[String].add, CString.to_s `{
		char **mem;
		int m;
		Array_of_String ret;

		mem = self->gr_mem;
		ret = new_Array_of_String();

		for (m = 0; mem[m] != NULL; m++)
			Array_of_String_add(ret, CString_to_s(mem[m]));

		return ret;
	`}
end
lib/posix/posix.nit:15,1--109,3