Skip to content

Commit

Permalink
allow unprivileged user to run 'makecache' and 'clean' with alternate…
Browse files Browse the repository at this point in the history
… config
  • Loading branch information
oliverkurth committed Oct 7, 2024
1 parent a4aee1a commit 82ca75b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
25 changes: 7 additions & 18 deletions client/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,30 +145,17 @@ TDNFRefreshSack(

if (nMetadataExpired)
{
if (gEuid)
{
if (!pTdnf->pArgs->nCacheOnly)
{
pr_err("\ntdnf repo cache needs to be refreshed\n"
"You can use one of the below methods to workaround this\n"
"1. Login as root & refresh cache\n"
"2. Use -c (--config) option & create repo cache where you have access\n"
"3. Use -C (--cacheonly) & use existing cache in the system\n\n");
}
goto cleanup;
}

dwError = TDNFRepoRemoveCache(pTdnf, pRepo);
if (dwError == ERROR_TDNF_FILE_NOT_FOUND)
{
dwError = 0;//Ignore non existent folders
dwError = 0; // ignore not existing folders
}
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFRemoveSolvCache(pTdnf, pRepo);
if (dwError == ERROR_TDNF_FILE_NOT_FOUND)
{
dwError = 0;//Ignore non existent folders
dwError = 0; // ignore not existing folders
}
BAIL_ON_TDNF_ERROR(dwError);
}
Expand All @@ -179,9 +166,11 @@ TDNFRefreshSack(
}
if (dwError && pRepo->nSkipIfUnavailable)
{
pRepo->nEnabled = 0;
pr_info("Disabling Repo: '%s'\n", pRepo->pszName);
dwError = 0;
if (dwError != (ERROR_TDNF_SYSTEM_BASE + EACCES)) {
pRepo->nEnabled = 0;
pr_info("Disabling Repo: '%s'\n", pRepo->pszName);
dwError = 0;
}
}
BAIL_ON_TDNF_ERROR(dwError);
}
Expand Down
2 changes: 1 addition & 1 deletion client/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ TDNFTouchFile(
}

old_mask = umask(022);
fd = creat(pszFile, S_IRUSR | S_IRGRP | S_IROTH);
fd = creat(pszFile, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd < 0)
{
if (errno == EEXIST)
Expand Down
14 changes: 13 additions & 1 deletion tools/cli/lib/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,19 @@ uint32_t
TDNFCliRefresh(
PTDNF_CLI_CONTEXT pContext)
{
return TDNFRefresh(pContext->hTdnf);
uint32_t dwError = 0;
dwError = TDNFRefresh(pContext->hTdnf);

if (dwError == ERROR_TDNF_SYSTEM_BASE + EACCES) {
if (geteuid()) {
pr_err("\ntdnf repo cache needs to be refreshed but you have insufficient permissions\n"
"You can use one of the below methods to workaround this\n"
"1. Login as root and refresh cache\n"
"2. Use -c (--config) with a configuration file that has 'cachedir' set to a directory where you have access\n"
"3. Use -C (--cacheonly) and use the existing cache in the system\n\n");
}
}
return dwError;
}

static
Expand Down
4 changes: 2 additions & 2 deletions tools/cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static TDNF_CLI_CMD_MAP arCmdMap[] =
{"check", TDNFCliCheckCommand, false},
{"check-local", TDNFCliCheckLocalCommand, false},
{"check-update", TDNFCliCheckUpdateCommand, false},
{"clean", TDNFCliCleanCommand, true},
{"clean", TDNFCliCleanCommand, false},
{"count", TDNFCliCountCommand, false},
{"distro-sync", TDNFCliDistroSyncCommand, true},
{"downgrade", TDNFCliDowngradeCommand, true},
Expand All @@ -25,7 +25,7 @@ static TDNF_CLI_CMD_MAP arCmdMap[] =
{"info", TDNFCliInfoCommand, false},
{"install", TDNFCliInstallCommand, true},
{"list", TDNFCliListCommand, false},
{"makecache", TDNFCliMakeCacheCommand, true},
{"makecache", TDNFCliMakeCacheCommand, false},
{"mark", TDNFCliMarkCommand, false},
{"provides", TDNFCliProvidesCommand, false},
{"whatprovides", TDNFCliProvidesCommand, false},
Expand Down

0 comments on commit 82ca75b

Please sign in to comment.