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

Handle cases when auth groups are unset #353

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 14 additions & 0 deletions pappl/client-accessors.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,17 @@ papplClientSetUsername(
client->username[0] = '\0';
}
}


//
// '_papplClientGroupIsEmpty()' - Check if group is empty
//

bool // O - `true` if empty, `false` if set
_papplClientGroupIsEmpty(const char *group) // I - Group name
{
if (!group || !group[0])
return (true);

return (false);
}
6 changes: 6 additions & 0 deletions pappl/client-auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ _papplClientIsAuthorizedForGroup(
return (HTTP_STATUS_BAD_REQUEST);
}
}
else
{
// If there is no Authorization field, no group and we are on localhost - continue
if (_papplClientGroupIsEmpty(group) && httpAddrIsLocalhost(httpGetAddress(client->http)))
return (HTTP_STATUS_CONTINUE);
}

// If we get there then we don't have any authorization value we can use...
return (HTTP_STATUS_UNAUTHORIZED);
Expand Down
1 change: 1 addition & 0 deletions pappl/client-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ extern char *_papplClientCreateTempFile(pappl_client_t *client, const void *dat
extern void _papplClientDelete(pappl_client_t *client) _PAPPL_PRIVATE;
extern void _papplClientFlushDocumentData(pappl_client_t *client) _PAPPL_PRIVATE;
extern const char *_papplClientGetAuthWebScheme(pappl_client_t *client) _PAPPL_PRIVATE;
extern bool _papplClientGroupIsEmpty(const char *group) _PAPPL_PRIVATE;
extern bool _papplClientHaveDocumentData(pappl_client_t *client) _PAPPL_PRIVATE;
extern http_status_t _papplClientIsAuthorizedForGroup(pappl_client_t *client, bool allow_remote, const char *group, gid_t groupid) _PAPPL_PUBLIC;
extern bool _papplClientProcessHTTP(pappl_client_t *client) _PAPPL_PRIVATE;
Expand Down
14 changes: 13 additions & 1 deletion pappl/printer-ipp.c
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,21 @@ bool // O - `true` on success, `false` on failure
_papplPrinterIsAuthorized(
pappl_client_t *client) // I - Client
{
const char *username; // Current username
ipp_attribute_t *attr; // requesting-user-name attribute

http_status_t code = _papplClientIsAuthorizedForGroup(client, true, client->printer->print_group, client->printer->print_gid);

if (code == HTTP_STATUS_CONTINUE && client->job && client->job->username && strcmp(client->username, client->job->username))
// In case of local connections, use requesting-user-name attribute as username later if client username is missing
if (code == HTTP_STATUS_CONTINUE)
{
if (!client->username[0] && (attr = ippFindAttribute(client->request, "requesting-user-name", IPP_TAG_NAME)) != NULL)
username = ippGetString(attr, 0, NULL);
else
username = client->username;
}

if (code == HTTP_STATUS_CONTINUE && client->job && client->job->username && strcmp(username, client->job->username))
{
// Not the owner, try authorizing with admin group...
code = _papplClientIsAuthorizedForGroup(client, true, client->system->admin_group, client->system->admin_gid);
Expand Down
Loading