1 /* sysutils.h - System utility functions for Gnupg
2  *	Copyright (C) 2002 Free Software Foundation, Inc.
3  *
4  * This file is part of GnuPG.
5  *
6  * This file is free software; you can redistribute it and/or modify
7  * it under the terms of either
8  *
9  *   - the GNU Lesser General Public License as published by the Free
10  *     Software Foundation; either version 3 of the License, or (at
11  *     your option) any later version.
12  *
13  * or
14  *
15  *   - the GNU General Public License as published by the Free
16  *     Software Foundation; either version 2 of the License, or (at
17  *     your option) any later version.
18  *
19  * or both in parallel, as here.
20  *
21  * This file is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, see <https://www.gnu.org/licenses/>.
28  */
29 
30 #ifndef GNUPG_COMMON_SYSUTILS_H
31 #define GNUPG_COMMON_SYSUTILS_H
32 
33 /* Because we use system handles and not libc low level file
34    descriptors on W32, we need to declare them as HANDLE (which
35    actually is a plain pointer).  This is required to eventually
36    support 64 bits Windows systems.  */
37 #ifdef HAVE_W32_SYSTEM
38 typedef void *gnupg_fd_t;
39 #define GNUPG_INVALID_FD ((void*)(-1))
40 #define INT2FD(s) ((void *)(s))
41 #define FD2INT(h) ((unsigned int)(h))
42 #else
43 typedef int gnupg_fd_t;
44 #define GNUPG_INVALID_FD (-1)
45 #define INT2FD(s) (s)
46 #define FD2INT(h) (h)
47 #endif
48 
49 #ifdef HAVE_STAT
50 # include <sys/stat.h>
51 #endif
52 
53 struct gnupg_dir_s;
54 typedef struct gnupg_dir_s *gnupg_dir_t;
55 struct gnupg_dirent_s
56 {
57   /* We don't have a d_ino because that can't be used on Windows
58    * anyway.  D_NAME is a pointer into the gnupg_dir_s which has a
59    * static buffer or allocates sufficient space as needed.  This is
60    * only valid after gnupg_readdir. */
61   char *d_name;
62 };
63 typedef struct gnupg_dirent_s *gnupg_dirent_t;
64 
65 
66 void trap_unaligned (void);
67 int  disable_core_dumps (void);
68 int  enable_core_dumps (void);
69 void enable_special_filenames (void);
70 const unsigned char *get_session_marker (size_t *rlen);
71 unsigned int get_uint_nonce (void);
72 /*int check_permissions (const char *path,int extension,int checkonly);*/
73 void gnupg_sleep (unsigned int seconds);
74 void gnupg_usleep (unsigned int usecs);
75 int translate_sys2libc_fd (gnupg_fd_t fd, int for_write);
76 int translate_sys2libc_fd_int (int fd, int for_write);
77 int check_special_filename (const char *fname, int for_write, int notranslate);
78 FILE *gnupg_tmpfile (void);
79 void gnupg_reopen_std (const char *pgmname);
80 void gnupg_inhibit_set_foregound_window (int yes);
81 void gnupg_allow_set_foregound_window (pid_t pid);
82 int  gnupg_remove (const char *fname);
83 gpg_error_t gnupg_rename_file (const char *oldname, const char *newname,
84                                int *block_signals);
85 int gnupg_mkdir (const char *name, const char *modestr);
86 int gnupg_chdir (const char *name);
87 int gnupg_rmdir (const char *name);
88 int gnupg_chmod (const char *name, const char *modestr);
89 char *gnupg_mkdtemp (char *template);
90 int  gnupg_setenv (const char *name, const char *value, int overwrite);
91 int  gnupg_unsetenv (const char *name);
92 char *gnupg_getcwd (void);
93 gpg_err_code_t gnupg_access (const char *name, int mode);
94 #ifdef HAVE_STAT
95 int gnupg_stat (const char *name, struct stat *statbuf);
96 #endif /*HAVE_STAT*/
97 int gnupg_open (const char *name, int flags, unsigned int mode);
98 
99 gnupg_dir_t gnupg_opendir (const char *name);
100 gnupg_dirent_t gnupg_readdir (gnupg_dir_t gdir);
101 int gnupg_closedir (gnupg_dir_t gdir);
102 
103 gpg_error_t gnupg_chuid (const char *user, int silent);
104 char *gnupg_get_socket_name (int fd);
105 int gnupg_fd_valid (int fd);
106 
107 gpg_error_t gnupg_inotify_watch_delete_self (int *r_fd, const char *fname);
108 gpg_error_t gnupg_inotify_watch_socket (int *r_fd, const char *socket_name);
109 int gnupg_inotify_has_name (int fd, const char *name);
110 
111 
112 #ifdef HAVE_W32_SYSTEM
113 void gnupg_w32_set_errno (int ec);
114 void *w32_get_user_sid (void);
115 
116 #include "../common/w32help.h"
117 
118 #endif /*HAVE_W32_SYSTEM*/
119 
120 #endif /*GNUPG_COMMON_SYSUTILS_H*/
121