Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/src/sudo_edit.h
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 2021 Todd C. Miller <[email protected]>
5
*
6
* Permission to use, copy, modify, and distribute this software for any
7
* purpose with or without fee is hereby granted, provided that the above
8
* copyright notice and this permission notice appear in all copies.
9
*
10
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
19
#ifndef SUDO_EDIT_H
20
#define SUDO_EDIT_H
21
22
/*
23
* Directory open flags for use with openat(2).
24
* Use O_SEARCH/O_PATH and/or O_DIRECTORY where possible.
25
*/
26
#if defined(O_SEARCH)
27
# if defined(O_DIRECTORY)
28
# define DIR_OPEN_FLAGS (O_SEARCH|O_DIRECTORY)
29
# else
30
# define DIR_OPEN_FLAGS (O_SEARCH)
31
# endif
32
#elif defined(O_PATH)
33
# if defined(O_DIRECTORY)
34
# define DIR_OPEN_FLAGS (O_PATH|O_DIRECTORY)
35
# else
36
# define DIR_OPEN_FLAGS (O_PATH)
37
# endif
38
#elif defined(O_DIRECTORY)
39
# define DIR_OPEN_FLAGS (O_RDONLY|O_DIRECTORY)
40
#else
41
# define DIR_OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
42
#endif
43
44
/* copy_file.c */
45
int sudo_copy_file(const char *src, int src_fd, off_t src_len, const char *dst, int dst_fd, off_t dst_len);
46
bool sudo_check_temp_file(int tfd, const char *tname, uid_t uid, struct stat *sb);
47
48
/* edit_open.c */
49
struct sudo_cred;
50
void switch_user(uid_t euid, gid_t egid, int ngroups, GETGROUPS_T *groups);
51
int sudo_edit_open(char *path, int oflags, mode_t mode, unsigned int sflags, const struct sudo_cred *user_cred, const struct sudo_cred *cur_cred);
52
int dir_is_writable(int dfd, const struct sudo_cred *user_cred, const struct sudo_cred *cur_cred);
53
bool sudo_edit_parent_valid(char *path, unsigned int sflags, const struct sudo_cred *user_cred, const struct sudo_cred *cur_cred);
54
55
#endif /* SUDO_EDIT_H */
56
57