netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
cnid_metad.c File Reference

cnid_dbd metadaemon to start up cnid_dbd upon request from afpd. More...

`#include <unistd.h>`
`#include <errno.h>`
`#include <signal.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <sys/param.h>`
`#include <sys/resource.h>`
`#include <sys/socket.h>`
`#include <sys/time.h>`
`#include <sys/types.h>`
`#include <sys/uio.h>`
`#include <sys/un.h>`
`#include <sys/wait.h>`
`#include <time.h>`
`#include <bstrlib.h>`
`#include <pwd.h>`
`#include <grp.h>`
`#include <atalk/util.h>`
`#include <atalk/logger.h>`
`#include <atalk/cnid_bdb_private.h>`
`#include <atalk/compat.h>`
`#include <atalk/errchk.h>`
`#include <atalk/iniparser_util.h>`
`#include <atalk/netatalk_conf.h>`
`#include <atalk/volume.h>`
`#include "usockfd.h"`

## Data Structures
struct | server

## Macros
#define | WEXITSTATUS(stat_val)
#define | WIFEXITED(stat_val)
#define | WIFSTOPPED(status)
#define | WIFSIGNALED(status)
#define | WTERMSIG(status)
#define | SWITCH_TO_GID(gid)
#define | SWITCH_TO_UID(uid)
#define | DBHOME ".AppleDB"
#define | DBHOMELEN 8
#define | MAXSPAWN 3
#define | TESTTIME 10
#define | MAXVOLS 4096
#define | DEFAULTHOST "localhost"
#define | DEFAULTPORT "4700"

## Functions
static void | daemon_exit (int i)
static void | sig_handler (int sig)
static struct server * | test_usockfn (const char *path)
int | maybe_start_dbd (const AFPObj *obj, char *dbdpn, const char *volpath, const char *username)
| Pass connection request to existing cnid_dbd process or start a new one.
static int | set_dbdir (const char *dbdir, const char *vpath)
static void | catch_child (int sig)
static void | set_signal (void)
static int | setlimits (void)
static uid_t | uid_from_name (const char *name)
int | main (int argc, char *argv[])

## Variables
static int | srvfd
static int | rqstfd
static volatile sig_atomic_t | sigchild = 0
static uint | maxvol
static struct server | srv [MAXVOLS]

## Detailed Description

cnid_dbd metadaemon to start up cnid_dbd upon request from afpd.

Here is how it works:

via TCP socket
1. afpd -------> cnid_metad
via UNIX domain socket
2. cnid_metad -------> cnid_dbd
passes afpd client fd
3. cnid_metad -------> cnid_dbd
Result:
via TCP socket
4. afpd -------> cnid_dbd

cnid_metad and cnid_dbd have been converted to non-blocking IO in 2010.

## Macro Definition Documentation

## ◆ DBHOME

#define DBHOME ".AppleDB"

## ◆ DBHOMELEN

#define DBHOMELEN 8

## ◆ DEFAULTHOST

#define DEFAULTHOST "localhost"

## ◆ DEFAULTPORT

#define DEFAULTPORT "4700"

## ◆ MAXSPAWN

#define MAXSPAWN 3

Max times respawned in..

## ◆ MAXVOLS

#define MAXVOLS 4096

## ◆ SWITCH_TO_GID

#define SWITCH_TO_GID | ( |  | gid | ) |

Value:
((setegid(gid) < 0 || setgid(gid) < 0) ? -1 : 0)

## ◆ SWITCH_TO_UID

#define SWITCH_TO_UID | ( |  | uid | ) |

Value:
((setuid(uid) < 0 || seteuid(uid) < 0 || setuid(uid) < 0) ? -1 : 0)

## ◆ TESTTIME

#define TESTTIME 10

this much seconds apfd client tries to to reconnect every 5 secondes, catch it

## ◆ WEXITSTATUS

#define WEXITSTATUS | ( |  | stat_val | ) |

Value:
((unsigned)(stat_val) >> 8)

## ◆ WIFEXITED

#define WIFEXITED | ( |  | stat_val | ) |

Value:
(((stat_val) & 255) == 0)

## ◆ WIFSIGNALED

#define WIFSIGNALED | ( |  | status | ) |

Value:
(!WIFSTOPPED(status) && !WIFEXITED(status))
WIFEXITED
#define WIFEXITED(stat_val)
Definition cnid_metad.c:60
WIFSTOPPED
#define WIFSTOPPED(status)
Definition cnid_metad.c:63
status
static char * status
Definition pap.c:93

## ◆ WIFSTOPPED

#define WIFSTOPPED | ( |  | status | ) |

Value:
(((status) & 0xff) == 0x7f)

## ◆ WTERMSIG

#define WTERMSIG | ( |  | status | ) |

Value:
((status) & 0x7f)

## Function Documentation

## ◆ catch_child()

void catch_child | ( | int | sig | ) |
| static

## ◆ daemon_exit()

void daemon_exit | ( | int | i | ) |
| static

## ◆ main()

int main | ( | int | argc,
|  | char * | argv[] )

## ◆ maybe_start_dbd()

int maybe_start_dbd | ( | const AFPObj * | obj,
|  | char * | dbdpn,
|  | const char * | volpath,
|  | const char * | username )

Pass connection request to existing cnid_dbd process or start a new one.

Parameters

  [in] | obj | handle
  [in] | dbdpn | Path to cnid_dbd binary
  [in] | volpath | Path of AFP volume
  [in] | username | Optional username, may be NULL

Returns
  0 on success, -1 on error

## ◆ set_dbdir()

int set_dbdir | ( | const char * | dbdir,
|  | const char * | vpath )
| static

## ◆ set_signal()

void set_signal | ( | void |  | ) |
| static

## ◆ setlimits()

int setlimits | ( | void |  | ) |
| static

## ◆ sig_handler()

void sig_handler | ( | int | sig | ) |
| static

## ◆ test_usockfn()

struct server * test_usockfn | ( | const char * | path | ) |
| static

## ◆ uid_from_name()

uid_t uid_from_name | ( | const char * | name | ) |
| static

## Variable Documentation

## ◆ maxvol

uint maxvol
| static

## ◆ rqstfd

int rqstfd
| static

## ◆ sigchild

volatile sig_atomic_t sigchild = 0
| static

## ◆ srv

struct server srv[MAXVOLS]
| static

## ◆ srvfd

int srvfd
| static