Skip to content

Commit

Permalink
rtrim /etc/cron.allow|deny
Browse files Browse the repository at this point in the history
  • Loading branch information
a-detiste committed Dec 12, 2014
1 parent 9ff1e4b commit 7b93059
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/bin/crontab_setuid.c
Expand Up @@ -15,6 +15,12 @@ void end(char * msg){
exit(1);
}

void rtrim(char *str){
int n=strlen(str);
while((--n>0)&&(str[n]==' ' || str[n]=='\n'));
str[n+1]='\0';
}

int main(int argc, char *argv[]) {
if (!getuid()) end("root doesn't need this helper");

Expand Down Expand Up @@ -51,7 +57,7 @@ int main(int argc, char *argv[]) {
if (file != NULL) {
int allowed=0;
while(fgets(users, sizeof(users), file)) {
strtok(users, "\n");
rtrim(users);
if (!strcmp(pw->pw_name, users)) {
allowed=1;
break;
Expand All @@ -63,7 +69,7 @@ int main(int argc, char *argv[]) {
file = fopen("/etc/cron.deny", "r");
if (file != NULL) {
while(fgets(users, sizeof(users), file)) {
strtok(users, "\n");
rtrim(users);
if (!strcmp(pw->pw_name, users)) {
fclose(file);
end("you are in /etc/cron.deny");
Expand Down

0 comments on commit 7b93059

Please sign in to comment.