Skip to content

Commit

Permalink
Remove unused functions in util_getuid
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Aug 8, 2024
1 parent f340837 commit aa2caf7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 58 deletions.
8 changes: 0 additions & 8 deletions lib/include/ert/util/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,6 @@ void util_copy_directory_content(const char *src_path, const char *target_path);
void util_copy_directory(const char *, const char *);
#endif

#ifdef ERT_HAVE_GETUID
uid_t util_get_entry_uid(const char *file);
mode_t util_getmode(const char *filename);
bool util_addmode_if_owner(const char *filename, mode_t add_mode);
bool util_delmode_if_owner(const char *filename, mode_t del_mode);
bool util_chmod_if_owner(const char *filename, mode_t new_mode);
#endif

int util_forward_line(FILE *, bool *);
void util_rewind_line(FILE *);

Expand Down
51 changes: 1 addition & 50 deletions lib/util/util_getuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,7 @@
#include <sys/types.h>
#include <unistd.h>

uid_t util_get_entry_uid(const char *file) {
stat_type buffer;
util_stat(file, &buffer);
return buffer.st_uid;
}

mode_t util_getmode(const char *file) {
stat_type buffer;
util_stat(file, &buffer);
return buffer.st_mode;
}

bool util_chmod_if_owner(const char *filename, mode_t new_mode) {
static bool util_chmod_if_owner(const char *filename, mode_t new_mode) {
stat_type buffer;
uid_t exec_uid = getuid();
util_stat(filename, &buffer);
Expand All @@ -37,43 +25,6 @@ bool util_chmod_if_owner(const char *filename, mode_t new_mode) {
return false; /* No update performed. */
}

/*
IFF the current uid is also the owner of the file the current
function will add the permissions specified in the add_mode variable
to the file.
The function simulates the "chmod +???" behaviour of the shell
command. If the mode of the file is changed the function will return
true, otherwise it will return false.
*/

bool util_addmode_if_owner(const char *filename, mode_t add_mode) {
stat_type buffer;
util_stat(filename, &buffer);

{
mode_t current_mode = buffer.st_mode & (S_IRWXU + S_IRWXG + S_IRWXO);
mode_t target_mode = (current_mode | add_mode);

return util_chmod_if_owner(filename, target_mode);
}
}

/**
Implements shell chmod -??? behaviour.
*/
bool util_delmode_if_owner(const char *filename, mode_t del_mode) {
stat_type buffer;
util_stat(filename, &buffer);

{
mode_t current_mode = buffer.st_mode & (S_IRWXU + S_IRWXG + S_IRWXO);
mode_t target_mode = (current_mode - (current_mode & del_mode));

return util_chmod_if_owner(filename, target_mode);
}
}

/**
Only removes the last component in path.
*/
Expand Down

0 comments on commit aa2caf7

Please sign in to comment.