Tor  0.4.7.0-alpha-dev
Macros | Typedefs | Functions
dir.h File Reference

Header for dir.c. More...

#include "lib/cc/compat_compiler.h"
#include "lib/testsupport/testsupport.h"

Go to the source code of this file.

Macros

#define CPD_NONE   0
 
#define CPD_CREATE   (1u << 0)
 
#define CPD_CHECK   (1u << 1)
 
#define CPD_GROUP_OK   (1u << 2)
 
#define CPD_GROUP_READ   (1u << 3)
 
#define CPD_CHECK_MODE_ONLY   (1u << 4)
 
#define CPD_RELAX_DIRMODE_CHECK   (1u << 5)
 

Typedefs

typedef unsigned int cpd_check_t
 

Functions

int check_private_dir (const char *dirname, cpd_check_t check, const char *effective_user)
 
struct smartlist_ttor_listdir (const char *dirname)
 

Detailed Description

Header for dir.c.

Definition in file dir.h.

Typedef Documentation

◆ cpd_check_t

typedef unsigned int cpd_check_t

Possible behaviors for check_private_dir() on encountering a nonexistent directory; see that function's documentation for details.

Definition at line 20 of file dir.h.

Function Documentation

◆ check_private_dir()

int check_private_dir ( const char *  dirname,
cpd_check_t  check,
const char *  effective_user 
)

Check whether dirname exists and is private. If yes return 0. If dirname does not exist:

  • if check&CPD_CREATE, try to create it and return 0 on success.
  • if check&CPD_CHECK, and we think we can create it, return 0.
  • if check&CPD_CHECK is false, and the directory exists, return 0.
  • otherwise, return -1. If CPD_GROUP_OK is set, then it's okay if the directory is group-readable, but in all cases we create the directory mode 0700. If CPD_GROUP_READ is set, existing directory behaves as CPD_GROUP_OK and if the directory is created it will use mode 0750 with group read permission. Group read privileges also assume execute permission as norm for directories. If CPD_CHECK_MODE_ONLY is set, then we don't alter the directory permissions if they are too permissive: we just return -1. When effective_user is not NULL, check permissions against the given user and its primary group.

Definition at line 71 of file dir.c.

Referenced by hs_config_client_authorization(), and storage_dir_new().

◆ tor_listdir()

struct smartlist_t* tor_listdir ( const char *  dirname)

Return a new list containing the filenames in the directory dirname. Return NULL on error or if dirname is not a directory.

Definition at line 307 of file dir.c.

Referenced by dump_desc_populate_fifo_from_directory(), and hs_config_client_authorization().