Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
c0b7f88e
Commit
c0b7f88e
authored
Apr 11, 2022
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs_path: mock ownership checks
Provide a mock for file ownership for testability.
parent
c0dfd1ad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
src/util/fs_path.c
+42
-0
src/util/fs_path.h
+14
-0
No files found.
src/util/fs_path.c
View file @
c0b7f88e
...
...
@@ -1785,6 +1785,13 @@ done:
return
supported
;
}
static
git_fs_path__mock_owner_t
mock_owner
=
GIT_FS_PATH_MOCK_OWNER_NONE
;
void
git_fs_path__set_owner
(
git_fs_path__mock_owner_t
owner
)
{
mock_owner
=
owner
;
}
#ifdef GIT_WIN32
static
PSID
*
sid_dup
(
PSID
sid
)
{
...
...
@@ -1877,6 +1884,11 @@ int git_fs_path_owner_is_current_user(bool *out, const char *path)
PSID
owner_sid
=
NULL
,
user_sid
=
NULL
;
int
error
=
-
1
;
if
(
mock_owner
)
{
*
out
=
(
mock_owner
==
GIT_FS_PATH_MOCK_OWNER_CURRENT_USER
);
return
0
;
}
if
((
error
=
file_owner_sid
(
&
owner_sid
,
path
))
<
0
||
(
error
=
current_user_sid
(
&
user_sid
))
<
0
)
goto
done
;
...
...
@@ -1894,6 +1906,11 @@ int git_fs_path_owner_is_system(bool *out, const char *path)
{
PSID
owner_sid
;
if
(
mock_owner
)
{
*
out
=
(
mock_owner
==
GIT_FS_PATH_MOCK_OWNER_SYSTEM
);
return
0
;
}
if
(
file_owner_sid
(
&
owner_sid
,
path
)
<
0
)
return
-
1
;
...
...
@@ -1909,6 +1926,12 @@ int git_fs_path_owner_is_system_or_current_user(bool *out, const char *path)
PSID
owner_sid
=
NULL
,
user_sid
=
NULL
;
int
error
=
-
1
;
if
(
mock_owner
)
{
*
out
=
(
mock_owner
==
GIT_FS_PATH_MOCK_OWNER_SYSTEM
||
mock_owner
==
GIT_FS_PATH_MOCK_OWNER_CURRENT_USER
);
return
0
;
}
if
(
file_owner_sid
(
&
owner_sid
,
path
)
<
0
)
goto
done
;
...
...
@@ -1961,18 +1984,37 @@ static int fs_path_owner_is(bool *out, const char *path, uid_t *uids, size_t uid
int
git_fs_path_owner_is_current_user
(
bool
*
out
,
const
char
*
path
)
{
uid_t
userid
=
geteuid
();
if
(
mock_owner
)
{
*
out
=
(
mock_owner
==
GIT_FS_PATH_MOCK_OWNER_CURRENT_USER
);
return
0
;
}
return
fs_path_owner_is
(
out
,
path
,
&
userid
,
1
);
}
int
git_fs_path_owner_is_system
(
bool
*
out
,
const
char
*
path
)
{
uid_t
userid
=
0
;
if
(
mock_owner
)
{
*
out
=
(
mock_owner
==
GIT_FS_PATH_MOCK_OWNER_SYSTEM
);
return
0
;
}
return
fs_path_owner_is
(
out
,
path
,
&
userid
,
1
);
}
int
git_fs_path_owner_is_system_or_current_user
(
bool
*
out
,
const
char
*
path
)
{
uid_t
userids
[
2
]
=
{
geteuid
(),
0
};
if
(
mock_owner
)
{
*
out
=
(
mock_owner
==
GIT_FS_PATH_MOCK_OWNER_SYSTEM
||
mock_owner
==
GIT_FS_PATH_MOCK_OWNER_CURRENT_USER
);
return
0
;
}
return
fs_path_owner_is
(
out
,
path
,
userids
,
2
);
}
...
...
src/util/fs_path.h
View file @
c0b7f88e
...
...
@@ -731,6 +731,20 @@ int git_fs_path_normalize_slashes(git_str *out, const char *path);
bool
git_fs_path_supports_symlinks
(
const
char
*
dir
);
typedef
enum
{
GIT_FS_PATH_MOCK_OWNER_NONE
=
0
,
/* do filesystem lookups as normal */
GIT_FS_PATH_MOCK_OWNER_SYSTEM
=
1
,
GIT_FS_PATH_MOCK_OWNER_CURRENT_USER
=
2
,
GIT_FS_PATH_MOCK_OWNER_OTHER
=
3
}
git_fs_path__mock_owner_t
;
/**
* Sets the mock ownership for files; subsequent calls to
* `git_fs_path_owner_is_*` functions will return this data until cleared
* with `GIT_FS_PATH_MOCK_OWNER_NONE`.
*/
void
git_fs_path__set_owner
(
git_fs_path__mock_owner_t
owner
);
/**
* Verify that the file in question is owned by an administrator or system
* account.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment