dir.c File Reference

Read directories, and create directories with restrictive permissions. More...

#include "lib/fs/dir.h"
#include "lib/fs/path.h"
#include "lib/fs/userdb.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/log/win32err.h"
#include "lib/container/smartlist.h"
#include "lib/sandbox/sandbox.h"
#include "lib/malloc/malloc.h"
#include "lib/string/printf.h"
#include "lib/string/compat_string.h"
#include <dirent.h>
#include <pwd.h>
#include <grp.h>
#include <errno.h>
#include <string.h>

Go to the source code of this file.


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

Detailed Description

Read directories, and create directories with restrictive permissions.

Definition in file dir.c.

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()

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().