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)   ((unsigned)(stat_val) >> 8)
 
#define WIFEXITED(stat_val)   (((stat_val) & 255) == 0)
 
#define WIFSTOPPED(status)   (((status) & 0xff) == 0x7f)
 
#define WIFSIGNALED(status)   (!WIFSTOPPED(status) && !WIFEXITED(status))
 
#define WTERMSIG(status)   ((status) & 0x7f)
 
#define SWITCH_TO_GID(gid)   ((setegid(gid) < 0 || setgid(gid) < 0) ? -1 : 0)
 
#define SWITCH_TO_UID(uid)   ((setuid(uid) < 0 || seteuid(uid) < 0 || setuid(uid) < 0) ? -1 : 0)
 
#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 servertest_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)    ((setegid(gid) < 0 || setgid(gid) < 0) ? -1 : 0)

◆ SWITCH_TO_UID

#define SWITCH_TO_UID (   uid)    ((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)    ((unsigned)(stat_val) >> 8)

◆ WIFEXITED

#define WIFEXITED (   stat_val)    (((stat_val) & 255) == 0)

◆ WIFSIGNALED

#define WIFSIGNALED (   status)    (!WIFSTOPPED(status) && !WIFEXITED(status))

◆ WIFSTOPPED

#define WIFSTOPPED (   status)    (((status) & 0xff) == 0x7f)

◆ WTERMSIG

#define WTERMSIG (   status)    ((status) & 0x7f)

Function Documentation

◆ catch_child()

static void catch_child ( int  sig)
static

◆ daemon_exit()

static 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]objhandle
[in]dbdpnPath to cnid_dbd binary
[in]volpathPath of AFP volume
[in]usernameOptional username, may be NULL
Returns
0 on success, -1 on error

◆ set_dbdir()

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

◆ set_signal()

static void set_signal ( void  )
static

◆ setlimits()

static int setlimits ( void  )
static

◆ sig_handler()

static void sig_handler ( int  sig)
static

◆ test_usockfn()

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

◆ uid_from_name()

static 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