aboutsummaryrefslogtreecommitdiffstats
path: root/common/sysutils.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* gpg,gpgsm: New option --disable-fd-translation.Werner Koch2024-03-261-1/+2
| | | | | | | | | | | | | | * common/sysutils.c (no_translate_sys2libc_fd) [W32]: New global. (disable_translate_sys2libc_fd): New. (translate_sys2libc_fd): Make static and cobuild only for Windows. (translate_sys2libc_fd_int): Use no_translate_sys2libc_fd flag. * g10/gpg.c, sm/gpgsm.c (oDisableFdTranslation): New const. (opts): Add option "disable-fd-translation". (main): Set option. -- GnuPG-bug-id: 7060
* commond: Introduce FD2NUM to express conversion to number of fds.NIIBE Yutaka2023-07-181-0/+2
| | | | | | | | | | | | | | | | * common/sysutils.h (FD2NUM): New. * agent/call-pinentry.c (watch_sock): Use FD2NUM. * agent/gpg-agent.c (handle_connections): Likewise. * dirmngr/dirmngr.c (handle_connections): Likewise. * dirmngr/http.c (connect_with_timeout): Likewise. * kbx/keyboxd.c (handle_connections): Likewise. * scd/scdaemon.c (handle_connections): Likewise. * tpm2d/tpm2daemon.c (handle_connections): Likewise. -- GnuPG-bug-id: 6598 Signed-off-by: NIIBE Yutaka <[email protected]>
* common,w32: Fix FD2INT macro.NIIBE Yutaka2023-07-181-1/+5
| | | | | | | | | | * common/sysutils.h [HAVE_W32_SYSTEM] (FD2INT): Use intptr_t for 64-bit Windows. -- GnuPG-bug-id: 6598 Signed-off-by: NIIBE Yutaka <[email protected]>
* common: Introduce FD_DBG to display gnupg_fd_t value.NIIBE Yutaka2023-07-181-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * common/sysutils.h (FD_DBG): New. * agent/gpg-agent.c (check_nonce): Use FD_DBG. (do_start_connection_thread, start_connection_thread_ssh): Likewise. * common/iobuf.c (fd_cache_close, file_filter, do_open): Likewise. (do_iobuf_fdopen): Likewise. * dirmngr/dirmngr.c (check_nonce, start_connection_thread) (handle_connections): Likewise. * dirmngr/http.c (_my_socket_new, _my_socket_ref): Likewise. (_my_socket_unref): Likewise. * g10/decrypt.c (decrypt_message_fd): Likewise. * g10/encrypt.c (encrypt_crypt): Likewise. * g10/openfile.c (open_outfile): Likewise. * g10/plaintext.c (get_output_file, hash_datafile_by_fd): Likewise. * g10/verify.c (gpg_verify): Likewise. * kbx/keyboxd.c (check_nonce, do_start_connection_thread): Likewise. * scd/scdaemon.c (start_connection_thread): Likewise. (handle_connections): Likewise. * sm/gpgsm.c (open_es_fread, open_es_fwrite): Likewise. * tpm2d/tpm2daemon.c (start_connection_thread): Likewise. (handle_connections): Likewise. -- GnuPG-bug-id: 6597 Signed-off-by: NIIBE Yutaka <[email protected]>
* common: Add gnupg_check_special_filename.NIIBE Yutaka2023-07-111-0/+1
| | | | | | | | | | | | | | | * common/sysutils.h (gnupg_check_special_filename): New. * common/sysutils.c (gnupg_check_special_filename): New. * common/iobuf.c (translate_file_handle): Remove. (iobuf_is_pipe_filename): Use gnupg_check_special_filename. (do_open): Use gnupg_check_special_filename. * g10/plaintext.c (get_output_file): Use gnupg_check_special_filename and open_stream_nc. -- GnuPG-bug-id: 6580 Signed-off-by: NIIBE Yutaka <[email protected]>
* common,gpg,kbx: Factor out open_stream_nc.NIIBE Yutaka2023-07-101-0/+1
| | | | | | | | | | | | | * common/sysutils.h (open_stream_nc): New. * common/sysutils.c (open_stream_nc): New. * g10/decrypt.c (decrypt_message_fd): Use open_stream_nc. * g10/server.c (cmd_verify): Likewise. * kbx/kbxserver.c (prepare_outstream): Likewise. -- GnuPG-bug-id: 6580 Signed-off-by: NIIBE Yutaka <[email protected]>
* Merge branch 'STABLE-BRANCH-2-4' into masterWerner Koch2023-07-041-1/+1
|\
| * common,w32: Add missing GetLastError->errno mapping.Werner Koch2023-07-041-1/+1
| | | | | | | | | | | | | | * common/iobuf.c (file_filter, sock_filter): Add missing mapping. -- GnuPG-bug-id: 6528
* | tools:gpgtar: Clean up the use of --status-fd.NIIBE Yutaka2023-06-281-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | * common/sysutils.c (gnupg_parse_fdstr): Rename from gnupg_sys2libc_fdstr, as there is no translation any more. * common/sysutils.h (gnupg_parse_fdstr): Rename from gnupg_sys2libc_fdstr. * tools/gpgtar.c (main): Use gnupg_parse_fdstr, in cleaner way. -- GnuPG-bug-id: 6562 Signed-off-by: NIIBE Yutaka <[email protected]>
* | common,gpg,sm,tools: Don't remove translate_sys2libc_fd_int.NIIBE Yutaka2023-06-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * common/sysutils.c (translate_sys2libc_fd_int): Recover. (translate_sys2libc_fdstr): Remove. (check_special_filename): Follow the change. * common/sysutils.h (translate_sys2libc_fd_int): Recover. (translate_sys2libc_fdstr): Remove. * g10/gpg.c, g10/gpgv.c, sm/gpgsm.c: Revert the changes. * tools/gpg-auth.c, tools/gpg-card.c, tools/gpg-pair-tool.c: Likewise. * tools/gpg-wks-client.c, tools/gpgconf.c: Likewise. -- GnuPG-bug-id: 6551 Signed-off-by: NIIBE Yutaka <[email protected]>
* | common: Remove translate_sys2libc_fd_int.NIIBE Yutaka2023-06-231-1/+0
| | | | | | | | | | | | | | | | | | | | | | * common/sysutils.c (translate_sys2libc_fd_int): Remove. (check_special_filename): Use translate_sys2libc_fdstr. * common/sysutils.h (translate_sys2libc_fd_int): Remove. -- GnuPG-bug-id: 6551 Signed-off-by: NIIBE Yutaka <[email protected]>
* | common: Add gnupg_sys2libc_fdstr function.NIIBE Yutaka2023-06-231-0/+2
| | | | | | | | | | | | | | | | | | | | * common/sysutils.c (gnupg_sys2libc_fdstr): New. (translate_sys2libc_fdstr): Use gnupg_sys2libc_fdstr. -- GnuPG-bug-id: 6551 Signed-off-by: NIIBE Yutaka <[email protected]>
* | common: Add translate_sys2libc_fdstr.NIIBE Yutaka2023-06-221-0/+1
|/ | | | | | | | | * common/sysutils.c (translate_sys2libc_fdstr): New. -- GnuPG-bug-id: 6551 Signed-off-by: NIIBE Yutaka <[email protected]>
* w32: Move socketdir to LCOAL_APPDATAWerner Koch2021-08-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | | * common/homedir.c (is_gnupg_default_homedir): Use standard_homedir instead of the constant which makes a difference on Windows. (_gnupg_socketdir_internal) [W32]: Move the directory to LOCAL_APPDATA. (gnupg_cachedir): Remove unsued function. * common/sysutils.c (gnupg_rmdir): New. * tools/gpgconf.c (main): s/rmdir/gnupg_rmdir/. -- That is actually a more correct directory than APPDATA. This fixes a problem with installations where the APPDATA is non a network drive and the resulting socket filename is truncated in our socket helper function (because we use sockaddr also for our local socket emulation on Windows). LOCAL_APPDATA is expected to be on the local box and thus in the majority of cases the resulting socket file name will be short enough. GnuPG-bug-id: 5537 Signed-off-by: Werner Koch <[email protected]>
* gpg,w32: Fix gnupg_remove.Werner Koch2021-01-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | | * common/sysutils.c (map_w32_to_errno): New. (gnupg_w32_set_errno): New. (gnupg_remove) [w32]: Set ERRNO -- To support Unicode gnupg_remove was changed to use DeleteFileW and not properly tested because the code was alreadt used in Windows CE. However, ERRNO was not set and thus Dirmngr failed due to if (!gnupg_remove (fname)) log_info (_("removed stale te[...] file '%s'\n"), fname); else if (errno != ENOENT) { err = gpg_error_from_syserror (); log_error (_("problem remov[...] file '%s': %s\n"), fname, gpg_strerror (err)); goto leave; } GnuPG-bug-id: 5230
* common: New functions gnupg_opendir et al.Werner Koch2020-10-211-0/+18
| | | | | | | | | | | * common/sysutils.h (struct gnupg_dirent_s): New. * common/sysutils.c: Include dirent.h. (struct gnupg_dir_s): New. (gnupg_opendir, gnupg_readdir, gnupg_closedir): New. Change all callers of opendir, readdir, and closedir to use these functions. -- GnuPG-bug-id: 5098
* Replace all calls to stat by gnupg_stat.Werner Koch2020-10-201-0/+6
| | | | | | | | | | | * common/sysutils.c (gnupg_stat): New. * common/sysutils.h: Include sys/stat.h. -- Yet another wrapper for Unicode support on Windows. GnuPG-bug-id: 5098 Signed-off-by: Werner Koch <[email protected]>
* Replace most calls to open by a new wrapper.Werner Koch2020-10-201-0/+1
| | | | | | | | | | | | * common/sysutils.c (any8bitchar) [W32]: New. (gnupg_open): New. Replace most calls to open by this. * common/iobuf.c (any8bitchar) [W32]: New. (direct_open) [W32]: Use CreateFileW if needed. -- This is yet another step for full Unicode support on Windows. GnuPG-bug-id: 5098
* Replace all calls to access by gnupg_accessWerner Koch2020-10-201-0/+1
| | | | | | | | | | | | | | | | * common/sysutils.c (gnupg_access): New. Replace all calls to access by this wrapper. * common/homedir.c (w32_shgetfolderpath): Change to return UTF-8 directory name. (standard_homedir): Adjust for change. (w32_commondir, gnupg_cachedir): Ditto. -- Also use SHGetFolderPathW instead of SHGetFolderPathA on Windows. This is required to correctly handle non-ascii filenames on Windows. GnuPG-bug-id: 5098
* common: New helper function gnupg_chuid.Werner Koch2020-08-061-0/+1
| | | | | | | * common/sysutils.c (try_set_envvar): New. (gnupg_chuid): New. Signed-off-by: Werner Koch <[email protected]>
* gpg,sm: Avoid useless ASFW diagnostic in loopback mode.Werner Koch2020-01-131-0/+1
| | | | | | | | | | | * common/sysutils.c (inhibit_set_foregound_window): New var. (gnupg_inhibit_set_foregound_window): New func. (gnupg_allow_set_foregound_window): Use var. * g10/gpg.c (main): Inhibit in loopback mode. * sm/gpgsm.c (main): Ditto. -- Signed-off-by: Werner Koch <[email protected]>
* common: New functions gnupg_daemon_rootdir and gnupg_chdir.Werner Koch2017-07-251-1/+2
| | | | | | | | | | | * common/sysutils.c (gnupg_chdir): New. * common/homedir.c (gnupg_daemon_rootdir): New. * agent/gpg-agent.c (main): Use these functions instead chdir("/"). * dirmngr/dirmngr.c (main): Ditto. * scd/scdaemon.c (main): Ditto. -- Signed-off-by: Werner Koch <[email protected]>
* agent: Shutdown on removal of the home directory.Werner Koch2017-06-231-0/+1
| | | | | | | | | | | | | | | * common/sysutils.c (gnupg_inotify_watch_delete_self): New. * agent/gpg-agent.c (handle_connections): Rename my_inotify_fd to sock_inotify_fd. (handle_connections): Add home_inotify_fd to watch the home directory. -- GnuPG-bug-id: 3218 Note that we should add this also to dirmngr. And for non-Linux systems a stat in ticker should be implemented. Signed-off-by: Werner Koch <[email protected]>
* gpg,common: Make sure that all fd given are valid.Justus Winter2017-02-081-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * common/sysutils.c (gnupg_fd_valid): New function. * common/sysutils.h (gnupg_fd_valid): New declaration. * common/logging.c (log_set_file): Use the new function. * g10/cpr.c (set_status_fd): Likewise. * g10/gpg.c (main): Likewise. * g10/keylist.c (read_sessionkey_from_fd): Likewise. * g10/passphrase.c (set_attrib_fd): Likewise. * tests/openpgp/Makefile.am (XTESTS): Add the new test. * tests/openpgp/issue2941.scm: New file. -- Consider a situation where the user passes "--status-fd 3" but file descriptor 3 is not open. During the course of executing the rest of the commands, it's possible that gpg itself will open some files, and file descriptor 3 will get allocated. In this situation, the status information will be appended directly to whatever file happens to have landed on fd 3 (the trustdb? the keyring?). This is a potential data destruction issue for all writable file descriptor options: --status-fd --attribute-fd --logger-fd It's also a potential issue for readable file descriptor options, but the risk is merely weird behavior, and not data corruption: --override-session-key-fd --passphrase-fd --command-fd Fixes this by checking whether the fd is valid early on before using it. GnuPG-bug-id: 2941 Signed-off-by: Justus Winter <[email protected]>
* gpg,sm: Merge the two versions of check_special_filename.Werner Koch2016-11-291-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * sm/gpgsm.c (check_special_filename): Move to .. * common/sysutils.c (check_special_filename): here. Add arg NOTRANSLATE. (allow_special_filenames): New local var. (enable_special_filenames): New public functions. * sm/gpgsm.c (allow_special_filenames): Remove var. (main): Call enable_special_filenames instead of setting the var. (open_read, open_es_fread, open_es_fwrite): Call check_special_filename with 0 for NOTRANSLATE. * common/iobuf.c (special_names_enabled): Remove var. (iobuf_enable_special_filenames): Remove func. (check_special_filename): Remove func. (iobuf_is_pipe_filename): Call new version of the function with NOTRANSLATE set. (do_open): Ditto. * g10/gpg.c (main): Call enable_special_filenames instead of iobuf_enable_special_filenames. * g10/gpgv.c (main): Ditto. -- Note that we keep the iobuf.c:translate_file_handle because it is a bit different (for whatever reasons) than the translate function from sysutils. Signed-off-by: Werner Koch <[email protected]>
* common: Rename keybox_file_rename to gnupg_rename_file.Werner Koch2016-11-161-0/+2
| | | | | | | * kbx/keybox-util.c (keybox_file_rename): Rename to ... * common/sysutils.c (gnupg_rename_file): this. Change all callers. Signed-off-by: Werner Koch <[email protected]>
* Change all http://www.gnu.org in license notices to https://Werner Koch2016-11-051-1/+1
| | | | --
* common: New function gnupg_usleep.Werner Koch2016-10-311-0/+1
| | | | | | | | | | | * configure.ac (HAVE_NANOSLEEP): Test for nanosleep. * common/sysutils.c: Always include time.h. (gnupg_usleep): New. -- This function has been compiled from nPth and Libassuan. Signed-off-by: Werner Koch <[email protected]>
* agent,common: move get_socket_name() into common.Daniel Kahn Gillmor2016-10-271-0/+1
| | | | | | | | | | * agent/gpg-agent.c (get_socket_name): move to ... * common/sysutils.c (gnupg_get_socket_name): ... here. -- This allows us to use the same functionality in dirmngr as well. Signed-off-by: Daniel Kahn Gillmor <[email protected]>
* agent: Move inotify code to common and improve it.Werner Koch2016-10-151-0/+4
| | | | | | | | | | | | | | | | | | | | | | | * common/sysutils.c: Include sys/inotify.h. (my_error_from_syserror, my_error): New. (gnupg_inotify_watch_socket): New. (gnupg_inotify_has_name): New. * agent/gpg-agent.c: Do not include sys/inotify.h. (my_inotify_is_name): Remove. (handle_connections): Remove HAVE_INOTIFY_INIT protected code and use the new functions. -- When removing not a simple socket file but the entire directory the old code missed most events and thus did not worked properly. IN_DELETE_SELF has also been added to the watch list to detect a removal of the directory. However, in all tests that event was not triggered. The only way it could be triggered was by not watching the socket dir but an arbitary directory and rmdir that. GnuPG-bug-id: 2756 Signed-off-by: Werner Koch <[email protected]>
* agent: Sanitize permissions of the private key directory.Justus Winter2016-04-201-0/+1
| | | | | | | | | | | | | * agent/gpg-agent.c (create_private_keys_directory): Set permissions. * common/sysutils.c (modestr_to_mode): New function. (gnupg_mkdir): Use new function. (gnupg_chmod): New function. * common/sysutils.h (gnupg_chmod): New prototype. * tests/migrations/from-classic.test: Test migration with existing directory. GnuPG-bug-id: 2312 Signed-off-by: Justus Winter <[email protected]>
* Remove use of gnulib (part 2)Werner Koch2014-11-111-0/+1
| | | | | | | | | | | | | | | | * configure.ac (strpbrk): Add to AC_CHECK_FUNCS. (gl_EARLY): Remove. * common/stringhelp.c (strpbrk) [!HAVE_STRPBRK]: New. * common/sysutils.c (gnupg_mkdtemp): New. Based on code from glibc-2.6. (gnupg_setenv): Rewrite. (gnupg_unsetenv): Rewrite. * g10/exec.c: Include sysutils.h and replace mkdtemp by gnupg_mkdtemp. * g13/be-encfs.c: Ditto. * g13/mount.c: Ditto. * tools/symcryptrun.c (confucius_mktmpdir): Ditto. Signed-off-by: Werner Koch <[email protected]>
* common: Add function gnupg_getcwd.Werner Koch2014-04-221-0/+1
| | | | | | * tools/gpg-connect-agent.c (gnu_getcwd): Move to ... * common/sysutils.c (gnupg_getcwd): .. here. * tools/gpg-connect-agent.c (get_var_ext): Use gnupg_getcwd.
* ssh: Add support for Putty.Werner Koch2014-03-071-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * agent/gpg-agent.c [W32]: Include Several Windows header. (opts): Change help text for enable-ssh-support. (opts, main): Add option --enable-putty-support (putty_support, PUTTY_IPC_MAGIC, PUTTY_IPC_MAXLEN): New for W32. (agent_init_default_ctrl): Add and asssert call. (putty_message_proc, putty_message_thread): New. (handle_connections) [W32]: Start putty message thread. * common/sysutils.c (w32_get_user_sid): New for W32 only * tools/gpgconf-comp.c (gc_options_gpg_agent): Add --enable-ssh-support and --enable-putty-support. Make the configuration group visible at basic level. * agent/command-ssh.c (serve_mmapped_ssh_request): New for W32 only. -- This patch enables support for Putty. It has been tested with Putty 0.62 using an Unix created ssh key copied to the private-keys-v1.d directory on Windows and with a manually crafted sshcontrol file. It also works with a smartcard key. May thanks to gniibe who implemented a proxy in Python to test the putty/gpg-agent communication. Signed-off-by: Werner Koch <[email protected]> (cherry picked from commit 9f32499f99a0817f63f7a73b09bdcebe60d4775d) Resolved conflicts: NEWS agent/agent.h agent/gpg-agent.c: Convert from pth to npth. common/sysutils.c common/sysutils.h
* Change license for some files in common to LGPLv3+/GPLv2+.Werner Koch2012-04-201-5/+15
| | | | | | | | | | | | | | | | | | | | | | | Having the LGPL on the common GnuPG code helps to share code between GnuPG and related projects (like GPGME and Libassuan). This is good for interoperability and to reduces bugs. * common/asshelp.c, common/asshelp.h, common/asshelp2.c, common/b64dec.c * common/b64enc.c, common/convert.c, common/dns-cert.c * common/dns-cert.h common/exechelp-posix.c, common/exechelp-w32.c * common/exechelp-w32ce.c, common/exechelp.h, common/get-passphrase.c * common/get-passphrase.h, common/gettime.c, common/gpgrlhelp.c * common/helpfile.c, common/homedir.c, common/http.c, common/http.h * common/i18n.c, common/init.c, common/init.h, common/iobuf.c * common/iobuf.h, common/localename.c, common/membuf.c, common/membuf.h * common/miscellaneous.c, common/openpgp-oid.c, common/openpgpdefs.h * common/percent.c, common/pka.c, common/pka.h, common/session-env.c * common/session-env.h, common/sexp-parse.h, common/sexputil.c * common/signal.c, common/srv.c, common/srv.h, common/ssh-utils.c * common/ssh-utils.h, common/sysutils.c, common/sysutils.h * common/tlv.c, common/tlv.h, common/ttyio.c, common/ttyio.h * common/userids.c, common/userids.h, common/xasprintf.c: Change license to LGPLv3+/GPLv2+/
* Add code for explicit selection of pooled A records.Werner Koch2011-04-121-0/+1
| | | | | | | | | | | To better cope with round robin pooled A records like keys.gnupg.net we need to keep some information on unresponsive hosts etc. What we do now is to resolve the hostnames, remember them and select a random one. If a host is dead it will be marked and a different one selected. This is intended to solve the problem of long timeouts due to unresponsive hosts. The code is not yet finished but selection works.
* Whole lot of changes to support CE.Werner Koch2010-04-141-0/+3
|
* More changes for CE. gpgsm does now build and run a keylisting.Werner Koch2010-03-241-1/+1
|
* Merged jnlib into common.Werner Koch2010-03-101-1/+1
|
* Fix possible system freeze on Mac OS X.Werner Koch2009-05-191-3/+0
|
* g10/Marcus Brinkmann2008-06-251-10/+0
| | | | | | | | | | | | | | | | | | | | | | 2008-06-25 Marcus Brinkmann <[email protected]> * gpg.c (enum cmd_and_opt_values): Remove option oEnableW32HandleTranslation. (opts): Remove option --enable-w32-handle-translation. (main): Remove variable w32_handle_translation. common/ 2008-06-25 Marcus Brinkmann <[email protected]> Revert last three changes related to handle translation. * sysutils.c: (FD_TRANSLATE_MAX, fd_translate, fd_translate_len) (translate_table_init, translate_table_lookup): Removed. * iobuf.c (check_special_filename): Do not use translate_table_lookup. * sysutils.h (translate_table_init, translate_table_lookup): Remove prototypes.
* 2008-06-18 Marcus Brinkmann <[email protected]>Marcus Brinkmann2008-06-181-0/+10
| | | | | | | | | | | | | * sysutils.h (translate_table_init, translate_table_lookup): New prototypes. * sysutils.c: Include <ctype.h>. (FD_TRANSLATE_MAX): New macro. (fd_translate, fd_translate_len): New static variables. (translate_table_init, translate_table_lookup): New functions. (translate_sys2libc_fd_int): Translate file descriptor. * iobuf.c (check_special_filename): Translate handle values from special filenames.
* Poems for AllowSetForegroundWindow (W32)Werner Koch2008-02-141-0/+1
|
* Try to make sure that the standard descriptors are connected when callingWerner Koch2007-12-031-0/+1
| | | | | gpgsm.
* Use Assuan socket wrapper calls.Werner Koch2007-10-011-0/+4
| | | | | Made socket servers secure under Windows.
* Updated estream.Werner Koch2007-08-221-0/+1
| | | | | More changes for Windows.
* Translate all file descriptors received from assuan.Werner Koch2007-07-121-1/+16
|
* Changed to GPLv3.Werner Koch2007-07-041-4/+2
| | | | | Removed intl/.
* More W32 related changesWerner Koch2007-06-261-1/+1
|
* Fixed a problem in estream-printf.c.Werner Koch2007-06-251-0/+1
| | | | | Changes for Windows (gpgsm -k does now work). Minor cleanups.