Tor 0.4.9.8
Loading...
Searching...
No Matches
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.

Functions

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 check_and_create_data_directory(), check_or_create_data_subdir(), create_keys_directory(), dump_desc_create_dir(), dump_desc_init(), hs_check_service_private_dir(), hs_config_client_authorization(), storage_dir_new(), and store_permanent_client_auth_credentials().

◆ 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(), find_and_remove_client_auth_creds_file(), hs_config_client_authorization(), list_family_key_files_impl(), load_client_keys(), and storage_dir_rescan().