Rudiments: permissions Class Reference

Rudiments

Static Public Member Functions | List of all members
permissions Class Reference

## Static Public Member Functions
static bool | setFilePermissions (const char *filename, mode_t perms)
static bool | setFilePermissions (int32_t fd, mode_t perms)
static mode_t | evalPermString (const char *permstring)
static char * | evalPermOctal (mode_t mode)
static mode_t | everyoneReadWrite ()
static mode_t | everyoneReadWriteExecute ()
static mode_t | ownerRead ()
static mode_t | ownerWrite ()
static mode_t | ownerExecute ()
static mode_t | ownerReadWrite ()
static mode_t | ownerReadExecute ()
static mode_t | ownerReadWriteExecute ()
static mode_t | groupRead ()
static mode_t | groupWrite ()
static mode_t | groupExecute ()
static mode_t | groupReadWrite ()
static mode_t | groupReadExecute ()
static mode_t | groupReadWriteExecute ()
static mode_t | othersRead ()
static mode_t | othersWrite ()
static mode_t | othersExecute ()
static mode_t | othersReadWrite ()
static mode_t | othersReadExecute ()
static mode_t | othersReadWriteExecute ()
static mode_t | saveInSwapSpace ()
static mode_t | setUserId ()
static mode_t | setGroupId ()

## Detailed Description

Permissions are access priveleges. Files, directories, semaphores and shared memory segments all have permissions associated with them.

There are 3 types of permissions: read, write and execute.

These permissions can be granted to:

1. The user that owns the object.
2. Other users in the group of the user that owns the object.
3. All other users.

The execute permission has 2 modifications which can be applied to it:

1. Set user id - the program will run as the user that owns it instead of as the user that ran it

1. Set group id - the program will run as the group that owns it instead of as the group of the user that ran it

The "sticky bit" may also be set on platforms that support it. When set, the file is saved in the system's swap space. As a side-effect, it cannot be deleted by a user other than the one that created it.

## Member Function Documentation

## ◆ evalPermOctal()

static char* permissions::evalPermOctal | ( | mode_t | mode | ) |
| static

The inverse of evalPermString(). Evaluates "mode" and returns a string representing the permissions.

## ◆ evalPermString()

static mode_t permissions::evalPermString | ( | const char * | permstring | ) |
| static

Return a permission defined in "permstring".

"permstring" should be the same format as displayed by the "ls -l" command.

The first 3 characters set permissions for the owner. The next 3 characters set permissions for the group. The next 3 characters set permissions for all others.

For example: rwxr-xr-x : read/execute for everyone and write for the owner rw-rw-r– : read for everyone and write for the owner and owner's group rw-r–r– : read for everyone and write for the owner rwsr-sr-x : read/execute for everyone, write for the owner and run as the user/group that owns the file rw-rw-rwt : read/write for everyone, and save the file in swap space

## ◆ everyoneReadWrite()

static mode_t permissions::everyoneReadWrite | ( |  | ) |
| static

Returns rw-rw-rw- (666) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ everyoneReadWriteExecute()

static mode_t permissions::everyoneReadWriteExecute | ( |  | ) |
| static

Returns rwxrwxrwx (777) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ groupExecute()

static mode_t permissions::groupExecute | ( |  | ) |
| static

Returns --—x— (010) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ groupRead()

static mode_t permissions::groupRead | ( |  | ) |
| static

Returns —r--— (040) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ groupReadExecute()

static mode_t permissions::groupReadExecute | ( |  | ) |
| static

Returns —r-x— (050) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ groupReadWrite()

static mode_t permissions::groupReadWrite | ( |  | ) |
| static

Returns —rw-— (060) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ groupReadWriteExecute()

static mode_t permissions::groupReadWriteExecute | ( |  | ) |
| static

Returns —rwx— (070) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ groupWrite()

static mode_t permissions::groupWrite | ( |  | ) |
| static

Returns -—w-— (020) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ othersExecute()

static mode_t permissions::othersExecute | ( |  | ) |
| static

Returns -----—x (001) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ othersRead()

static mode_t permissions::othersRead | ( |  | ) |
| static

Returns ---—r– (004) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ othersReadExecute()

static mode_t permissions::othersReadExecute | ( |  | ) |
| static

Returns ---—r-x (005) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ othersReadWrite()

static mode_t permissions::othersReadWrite | ( |  | ) |
| static

Returns ---—rw- (006) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ othersReadWriteExecute()

static mode_t permissions::othersReadWriteExecute | ( |  | ) |
| static

Returns ---—rwx (007) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ othersWrite()

static mode_t permissions::othersWrite | ( |  | ) |
| static

Returns ----—w- (002) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ ownerExecute()

static mode_t permissions::ownerExecute | ( |  | ) |
| static

Returns –x---— (100) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ ownerRead()

static mode_t permissions::ownerRead | ( |  | ) |
| static

Returns r-----— (400) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ ownerReadExecute()

static mode_t permissions::ownerReadExecute | ( |  | ) |
| static

Returns r-x---— (500) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ ownerReadWrite()

static mode_t permissions::ownerReadWrite | ( |  | ) |
| static

Returns rw----— (600) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ ownerReadWriteExecute()

static mode_t permissions::ownerReadWriteExecute | ( |  | ) |
| static

Returns rwx---— (700) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ ownerWrite()

static mode_t permissions::ownerWrite | ( |  | ) |
| static

Returns -w----— (200) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ saveInSwapSpace()

static mode_t permissions::saveInSwapSpace | ( |  | ) |
| static

Returns -----—t permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ setFilePermissions() [1/2]

static bool permissions::setFilePermissions | ( | const char * | filename,
|  | mode_t | perms
| ) |  |
| static

Set the permissions on "filename" to "perms".

Returns true on success and false on failure.

## ◆ setFilePermissions() [2/2]

static bool permissions::setFilePermissions | ( | int32_t | fd,
|  | mode_t | perms
| ) |  |
| static

Set the permissions on the file associated with file descriptor "fd" to "perms".

Returns true on success and false on failure.

## ◆ setGroupId()

static mode_t permissions::setGroupId | ( |  | ) |
| static

Returns --—s— (g+s) permissions.

May be or'ed together with the result of another method to define a permission.

## ◆ setUserId()

static mode_t permissions::setUserId | ( |  | ) |
| static

Returns –s---— (u+s) permissions.

May be or'ed together with the result of another method to define a permission.