OpenVPN 3 Core Library
Loading...
Searching...
No Matches
umask.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#ifndef OPENVPN_COMMON_UMASK_H
13#define OPENVPN_COMMON_UMASK_H
14
15#include <sys/types.h>
16#include <sys/stat.h>
17
18namespace openvpn {
19// Note: not thread safe, since umask() is
20// documented to modify the process-wide file
21// mode creation mask.
22class UMask
23{
24 public:
25 UMask(mode_t new_umask)
26 {
27 umask_save = ::umask(new_umask);
28 }
29
31 {
32 ::umask(umask_save);
33 }
34
35 private:
36 UMask(const UMask &) = delete;
37 UMask &operator=(const UMask &) = delete;
38
39 mode_t umask_save;
40};
41
42struct UMaskPrivate : public UMask
43{
45 : UMask(077)
46 {
47 }
48};
49
50struct UMaskDaemon : public UMask
51{
53 : UMask(S_IWOTH)
54 {
55 }
56};
57} // namespace openvpn
58#endif
UMask & operator=(const UMask &)=delete
UMask(mode_t new_umask)
Definition umask.hpp:25
UMask(const UMask &)=delete
mode_t umask_save
Definition umask.hpp:39