netatalk 4.5.0
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)
| Fork, exit parent, setsid(), chdir("/"), close all fds.
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)
| Takes a buffer with a path, strips slashs, returns basename.
const char * | tmpdir (void)
| Find a suitable temporary directory for Netatalk.
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)
| chmod() wrapper for symlink and ACL handling
int | ostatat (int dirfd, const char *path, struct stat *st, int options)
| ostat/fsstatat multiplexer
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)
| safe basename() replacement
char * | strtok_quote (char *s, const char *delim)
| extended strtok allows the quoted strings
int | set_groups (AFPObj *obj, struct passwd *pwd)
const char * | print_groups (int ngroups, gid_t *groups)

## Variables
static uid_t | saved_uid = -1
static int | root_nesting = 0

## Detailed Description

Netatalk utility functions: unix

## Macro Definition Documentation

## ◆ GROUPSTR_BUFSIZE

#define GROUPSTR_BUFSIZE 1024

## Function Documentation

## ◆ basename_safe()

const char * basename_safe | ( | const char * | path | ) |

safe basename() replacement

Returns
  pointer to static buffer with basename of path

## ◆ become_root()

void become_root | ( | void |  | ) |

seteuid(0) and back, if either fails and panic != 0 we PANIC. Nesting is tracked: only the outermost become_root() elevates privileges and only the matching unbecome_root() drops them.

## ◆ closeall()

void closeall | ( | int | fd | ) |
| static

close all FDs >= a specified value

## ◆ daemonize()

int daemonize | ( | void |  | ) |

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

  [in] | path | path
  [in] | mode | requested mode
  [in] | st | stat() of path or NULL
  [in] | options | O_NOFOLLOW | O_NETATALK_ACL

Option descriptions:

- 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,
|  | const char * | path,
|  | struct stat * | st,
|  | int | options )

ostat/fsstatat multiplexer

ostatat mulitplexes ostat and fstatat.

Parameters

  [in] | dirfd | -1 gives AT_FDCWD
  [in] | path | pathname
  [in,out] | st | pointer to struct stat
  [in] | options | file 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 | ) |

realpath() replacement that always allocates storage for returned 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 |  | ) |

Find a suitable temporary directory for Netatalk.

Creates a subdirectory for current gid if it doesn't exist. The result should be copied immediately as it may be overwritten by a subsequent call.

## ◆ unbecome_root()

void unbecome_root | ( | void |  | ) |

## Variable Documentation

## ◆ root_nesting

int root_nesting = 0
| static

## ◆ saved_uid

uid_t saved_uid = -1
| static