Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Fix regression: specifying IPC privileges using UID #630

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/Common/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,22 @@ namespace usbguard
return rulefile_list;
}

bool isValidName(const std::string& name)
static bool isValidUID(const std::string& uid)
{
if (uid.empty()) {
return false;
}

for (char c : uid) {
if (!std::isdigit(c)) {
return false;
}
}

return true;
}

static bool isValidName(const std::string& name)
{
const char* s = name.data();

Expand All @@ -568,6 +583,10 @@ namespace usbguard
return true;
}

bool isValidNameOrUID(const std::string& input) {
return isValidName(input) || isValidUID(input);
}

} /* namespace usbguard */

/* vim: set ts=2 sw=2 et */
3 changes: 1 addition & 2 deletions src/Common/Utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,11 @@ namespace usbguard
/**
* @brief Checks whether a given name is a valid group/user name
*
* User/group names must match [A-Za-z_][A-Za-z0-9_-]*[$]
*
* @param name Name to check
* @return True if given name is valid, false otherwise
*/
bool isValidName(const std::string& name);
bool isValidNameOrUID(const std::string& name);

} /* namespace usbguard */

Expand Down
4 changes: 2 additions & 2 deletions src/Library/public/usbguard/IPCServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ namespace usbguard
throw Exception("IPC access control", "name too long", name);
}

if (!isValidName(name)) {
throw Exception("IPC access control", "invalid name format", name);
if (!isValidNameOrUID(name)) {
throw Exception("IPC access control", "invalid name or UID format", name);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Library/public/usbguard/IPCServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ namespace usbguard
/**
* @brief Checks whether given name is a valid access control name.
*
* Name is a valid access control name iff:
* Name is a valid access control name if:
* 1. it is not longer then 32 characters
* 2. it matches regex [A-Za-z_][A-Za-z0-9_-]*[$]
* 2. it is aligned with the syntax of useradd(8)
*
* @param name Name to be verified.
* @throw Exception If \p name is not a valid access control name.
Expand Down
Loading