summaryrefslogtreecommitdiff
path: root/lib/fileutils.c
Commit message (Collapse)AuthorAgeFilesLines
* lib/fileutils: fix compiler warningKarel Zak2022-07-201-0/+4
| | | | | | | | | lib/fileutils.c: In function ‘dup_fd_cloexec’: lib/fileutils.c:75:35: warning: unused parameter ‘lowfd’ [-Wunused-parameter] int dup_fd_cloexec(int oldfd, int lowfd) ^ Addresses: https://github.com/util-linux/util-linux/issues/1755 Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: reopen floppy without O_NONBLOCKKarel Zak2022-01-201-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | Vladimir Sementsov-Ogievskiy wrote: > The commit "floppy: reintroduce O_NDELAY fix" was removed from kernel, > so we faced the bug described and discussed here: > https://bugzilla.suse.com/show_bug.cgi?id=3D1181018 > > Discussion in kernel list on reverting the commit: > https://www.spinics.net/lists/stable/msg493061.html > > In short, I can quote Jiri Kosina's comment: > > opening floppy device node with O_NONBLOCK is asking for all kinds > of trouble > > So opening floppy with O_NONBLOCK in blkid leads to failure of blkid, > probable failure of mount and unpleasant error messages in dmesg (see > also patch 02 for details). Based on patch from Vladimir. CC: Jiri Kosina <jkosina@suse.cz> Reported-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Tested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* login: add callback for close_range()Karel Zak2021-07-151-5/+3
| | | | | | | | Let's make it more robust for old kernels where is no close_range() or in cases when it's unsuccessful. Reported-by: Florian Weimer <fweimer@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* login: fix close_range() useKarel Zak2021-07-141-1/+1
| | | | | | | | | This new syscall comes with three arguments (see kernel commit 278a5fbaed89dacd04e9d052f4594ffd0e0585de). Not sure why util-linux assume only two. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1981729 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: use ul_prefix for close_all_fds() and mkdir_p()Karel Zak2021-01-281-3/+3
| | | | | | | The names are too generic and it makes problems in static libraries. Addresses: https://gitlab.com/cryptsetup/cryptsetup/-/issues/623 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: fix compiler warnings [-Wmaybe-uninitialized]Karel Zak2020-12-171-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* tests: (fileutils) remove unused codeKarel Zak2020-12-081-4/+0
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/fileutils: make close_all_fds() to be similar with close_range()Sami Kerola2020-12-031-20/+19
| | | | | | | | | | | | | The util-linux close_all_fds() serves the same purpose as close_range() that will over time obsolete local implementation completely. For upcoming few years it is best to have a fallback that uses same input arguments as the new system call. That allows surrounding code and variables not to be affected by version of mass file descriptor closing function. Proposed-by: Karel Zak <kzak@redhat.com> Reference: https://github.com/karelzak/util-linux/pull/1205#discussion_r534080128 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* ul_copy_file: make defines for return valuesEgor Chelak2020-11-091-5/+5
| | | | | Suggested-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
* ul_copy_file: add test programEgor Chelak2020-11-091-1/+7
| | | | | | Suggested-by: Karel Zak <kzak@redhat.com> Reviewed-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
* ul_copy_file: handle EAGAIN and EINTREgor Chelak2020-11-091-13/+4
| | | | | | | | | | | | I did this by implementing a function called sendfile_all() similar to read_all()/write_all(). The manpage for sendfile doesn't mention EINTR, but I decided to check it anyway, just in case. Suggested-by: Karel Zak <kzak@redhat.com> Reviewed-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
* ul_copy_file: use all_read/all_writeEgor Chelak2020-11-091-5/+5
| | | | | | Suggested-by: Karel Zak <kzak@redhat.com> Reviewed-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
* ul_copy_file: use BUFSSIZ for buffer sizeEgor Chelak2020-11-091-1/+1
| | | | | | Suggested-by: Karel Zak <kzak@redhat.com> Reviewed-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
* configure.ac: check for sendfileEgor Chelak2020-11-091-0/+6
| | | | | | | | | | Do note that according to man sendfile, "Other UNIX systems implement sendfile() with different semantics and prototypes." If this is something we care about, a better check is needed. Suggested-by: Karel Zak <kzak@redhat.com> Reviewed-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
* ul_copy_file: use sendfileEgor Chelak2020-11-091-2/+28
| | | | | | Suggested-by: Karel Zak <kzak@redhat.com> Reviewed-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
* vipw: move copyfile to the libEgor Chelak2020-11-091-0/+19
| | | | | | | | | | Also, a bug in pw_tmpfile was fixed: copyfile used tmp_file to report errors, but pw_tmpfile only assigned that variable _after_ calling copyfile. Suggested-by: Sami Kerola <kerolasa@iki.fi> Reviewed-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
* lib: add missing headers to .c filesKarel Zak2020-10-061-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/fileutils: add close_all_fds()Karel Zak2019-10-171-8/+68
| | | | | | | | | | The classic way which is based on file-descriptors table size is pretty expensive (due to table size) and forces code to do many unnecessary close() calls. It seems better to use /proc/self/fds and close used descriptors only. Addresses: https://github.com/karelzak/util-linux/issues/883 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: use unique ifdefs for testsKarel Zak2017-01-041-1/+1
| | | | | | | Let's use unique TEST_PROGRAM_<NAME> ifdefs to make build system more robust. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: provide fallback if mkostemp(3) missingRuediger Meier2016-02-291-1/+30
| | | | | | | It's missing on OSX. CC: Yuriy M. Kaminskiy <yumkam@gmail.com> Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* chsh, chfn, vipw: fix filenames collisionKarel Zak2015-08-241-14/+7
| | | | | | | | | | | | | | | | | | The utils when compiled WITHOUT libuser then mkostemp()ing "/etc/%s.XXXXXX" where the filename prefix is argv[0] basename. An attacker could repeatedly execute the util with modified argv[0] and after many many attempts mkostemp() may generate suffix which makes sense. The result maybe temporary file with name like rc.status ld.so.preload or krb5.keytab, etc. Note that distros usually use libuser based ch{sh,fn} or stuff from shadow-utils. It's probably very minor security bug. Addresses: CVE-2015-5224 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/fileutils: Add new dup_fd_cloexec functionGuillem Jover2015-06-081-0/+30
| | | | | | | | This function duplicates and marks a file descriptor as close-on-exec. Takes care of build and run-time support for the fcntl F_DUPFD_CLOEXEC command, and other errors. Signed-off-by: Guillem Jover <guillem@hadrons.org>
* lib/fileutils: xalloc stuff in library-like codeKarel Zak2014-06-181-4/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/fileutils: add stripoff_last_component() from libmountKarel Zak2014-06-091-0/+12
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/fileutils: add mkdir_p() from libmountKarel Zak2014-06-091-0/+36
|
* lib: use O_CLOEXEC in libcommonKarel Zak2013-04-031-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fileutils: xmkstemp() interface changeDave Reisner2012-06-021-3/+9
| | | | | | | | | | | We can not let the user control where TMPDIR is for this tempfile. This will be where we write the updated passwd file, and must be capable of being moved atomically with rename(2). Therefore, it cannot be on a different device, or setpwnam() and vipw/vigr programs will invariably fail with EXDEV. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/fileutils: add get_fd_tabsize()Karel Zak2012-04-231-0/+24
| | | | | | as a fallback for the function getdtablesize() Signed-off-by: Karel Zak <kzak@redhat.com>
* fileutils: differentiate xmkstemp and xfmkstempSami Kerola2012-03-181-13/+10
| | | | | | | | | | | | Let developer to choose, case by case, what sort of return value is best in her code. The xmkstemp() is for users who want file descriptor as return value of the function, xfmkstemp() will return FILE pointer. Proposed-By: Karel Zak <kzak@redhat.com> CC: Davidlohr Bueso <dave@gnu.org> Reference: http://marc.info/?l=util-linux-ng&m=133129570124003&w=2 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* xalloc: use xasprintf in all filesSami Kerola2012-03-181-2/+3
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib: add fileutils function collectionSami Kerola2012-03-181-0/+55
The fileutils contains xmkstemp function will create temporary file safe and reusable manner. Reference: http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO.html#TEMPORARY-FILES CC: Davidlohr Bueso <dave@gnu.org> Signed-off-by: Sami Kerola <kerolasa@iki.fi>