#include "common.h"
#include <sys/capability.h>
#include "util.h"
#include "pam_netns.h"
Go to the source code of this file.
Defines |
#define | MAXARGS 31 |
#define | ARGBUFLEN 100 |
#define | MEMORY_INC_STEP 100 |
Functions |
char * | create_arg (const char *fmt, void **arg) |
| Create an argument.
|
char ** | create_argl (const char *fmt,...) |
| Create an argument verctor.
|
void | sec_free (void **p) |
| Free memory space securely.
|
void | sec_free_argl (void ***pp) |
| Free memory space of argument list securely.
|
int | sec_close (int *fd) |
| Close a filedescritpro securely.
|
bool | check_caps (void) |
| Check proces capabilities.
|
int | set_file_perm (const char *file_path, uid_t uid, gid_t gid, mode_t mode) |
| Set file permissions.
|
Detailed Description
Little collection of useful helper functions
- Author:
- Julian Thome
- Date:
- 2010-08-25
Define Documentation
#define MEMORY_INC_STEP 100 |
Function Documentation
Check proces capabilities.
This function check if the CAP_SYS_ADMIN flag is setted for the calling proces.
- Return values:
-
| true | CAP_SYS_ADMIN flag is setted |
| false | CAP_SYS_ADMIN flag is not setted |
char* create_arg |
( |
const char * |
fmt, |
|
|
void ** |
arg | |
|
) |
| | |
Create an argument.
This function is usually not called directly. It creates a string using the format and the argument list.
- Parameters:
-
| fmt | The format |
| arg | The argument vector |
- Returns:
- The resulting char array
char** create_argl |
( |
const char * |
fmt, |
|
|
|
... | |
|
) |
| | |
Create an argument verctor.
This function takes multiple formats and associated arguments.
- Parameters:
-
| fmt | The format (Each format should be followed by the associated arguments if fmt isn't a simple string |
- Returns:
- The resulting argument vector
int sec_close |
( |
int * |
fd |
) |
|
Close a filedescritpro securely.
This function close an open filedescritor and sets it to -1.
- Parameters:
-
| fd | Pointer to an open filedescriptor |
- Return values:
-
| 0 | Filedescriptor successfully closed |
| <0 | Something went wrong |
void sec_free |
( |
void ** |
p |
) |
|
Free memory space securely.
This function frees the allocated memory which is accessible over the pointer p and set this pointer to NULL.
- Parameters:
-
| p | Pointer to memory which should be freed |
void sec_free_argl |
( |
void *** |
pp |
) |
|
Free memory space of argument list securely.
This function frees all pointers in the argument vector and the pointer to the argument vector itself and set them to NULL. Be sure that the last element of the argument vector is a NULL pointer !!
- Parameters:
-
| p | Pointer to memory which should be freed |
int set_file_perm |
( |
const char * |
file_path, |
|
|
uid_t |
uid, |
|
|
gid_t |
gid, |
|
|
mode_t |
mode | |
|
) |
| | |
Set file permissions.
This function sets the file permission of the file given by file_path.
- Parameters:
-
| file_path | The path of the file which permissions should be changed |
| uid | User ID to set |
| gid | Group ID to set |
| mode | Mode to set |
- Return values:
-
| 0 | Permissions successfully setted |
| -1 | Something went wrong |