netatalk  4.4.0dev
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
unix.c File Reference
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <atalk/acl.h>
#include <atalk/adouble.h>
#include <atalk/afp.h>
#include <atalk/compat.h>
#include <atalk/ea.h>
#include <atalk/errchk.h>
#include <atalk/logger.h>
#include <atalk/unix.h>
#include <atalk/util.h>
#include <atalk/vfs.h>

Macros

#define GROUPSTR_BUFSIZE   1024

Functions

static void closeall (int fd)
int run_cmd (const char *cmd, char **cmd_argv)
int daemonize (void)
void become_root (void)
void unbecome_root (void)
const char * getcwdpath (void)
 get cwd in static buffer
const char * fullpathname (const char *name)
 Request absolute path.
char * stripped_slashes_basename (char *p)
const char * tmpdir (void)
int ostat (const char *path, struct stat *buf, int options)
int ochown (const char *path, uid_t owner, gid_t group, int options)
int ochmod (char *path, mode_t mode, const struct stat *st, int options)
int ostatat (int dirfd _U_, const char *path, struct stat *st, int options)
int ochdir (const char *dir, int options)
 symlink safe chdir replacement
void randombytes (void *buf, int n)
int gmem (gid_t gid, int ngroups, gid_t *groups)
char * realpath_safe (const char *path)
const char * basename_safe (const char *path)
char * strtok_quote (char *s, const char *delim)
int set_groups (AFPObj *obj, struct passwd *pwd)
const char * print_groups (int ngroups, gid_t *groups)

Variables

static uid_t saved_uid = -1

Detailed Description

Netatalk utility functions

Macro Definition Documentation

◆ GROUPSTR_BUFSIZE

#define GROUPSTR_BUFSIZE   1024

Function Documentation

◆ basename_safe()

const char * basename_safe ( const char * path)

Returns pointer to static buffer with basename of path

◆ become_root()

void become_root ( void )

◆ closeall()

void closeall ( int fd)
static

◆ daemonize()

int daemonize ( void )

Daemonize

Fork, exit parent, setsid(), chdir("/"), close all fds

returns -1 on failure, but you can't do much except exit in that case since we may already have forked

◆ fullpathname()

const char * fullpathname ( const char * name)

Request absolute path.

Returns
Absolute filesystem path to object

◆ getcwdpath()

const char * getcwdpath ( void )

get cwd in static buffer

Returns
pointer to path or pointer to error messages on error

◆ gmem()

int gmem ( gid_t gid,
int ngroups,
gid_t * groups )

◆ ochdir()

int ochdir ( const char * dir,
int options )

symlink safe chdir replacement

Only chdirs to dir if it doesn't contain symlinks or if symlink checking is disabled

Returns
1 if a path element is a symlink, 0 otherwise, -1 on syserror

◆ ochmod()

int ochmod ( char * path,
mode_t mode,
const struct stat * st,
int options )

chmod() wrapper for symlink and ACL handling

Parameters
path(r) path
mode(r) requested mode
st(r) stat() of path or NULL
options(r) O_NOFOLLOW | O_NETATALK_ACL

Options description: O_NOFOLLOW: don't chmod() symlinks, do nothing, return 0 O_NETATALK_ACL: call chmod_acl() instead of chmod() O_IGNORE: ignore chmod() request, directly return 0

◆ ochown()

int ochown ( const char * path,
uid_t owner,
gid_t group,
int options )

◆ ostat()

int ostat ( const char * path,
struct stat * buf,
int options )

◆ ostatat()

int ostatat ( int dirfd _U_,
const char * path,
struct stat * st,
int options )

◆ print_groups()

const char * print_groups ( int ngroups,
gid_t * groups )

◆ randombytes()

void randombytes ( void * buf,
int n )

Store n random bytes an buf

◆ realpath_safe()

char * realpath_safe ( const char * path)

◆ run_cmd()

int run_cmd ( const char * cmd,
char ** cmd_argv )

Run command in a child and wait for it to finish

◆ set_groups()

int set_groups ( AFPObj * obj,
struct passwd * pwd )

◆ stripped_slashes_basename()

char * stripped_slashes_basename ( char * p)

Takes a buffer with a path, strips slashs, returns basename

Parameters
p(rw) path path may be "[/][dir/[...]]file" or "[/][dir/[...]]dir/[/]" Result is "file" or "dir"
Returns
pointer to basename in path buffer, buffer is possibly modified

◆ strtok_quote()

char * strtok_quote ( char * s,
const char * delim )

extended strtok allows the quoted strings modified strtok.c in glibc 2.0.6

◆ tmpdir()

const char * tmpdir ( void )

◆ unbecome_root()

void unbecome_root ( void )

Variable Documentation

◆ saved_uid

uid_t saved_uid = -1
static