Skip to content

Commit

Permalink
imposer duration limit
Browse files Browse the repository at this point in the history
  • Loading branch information
btovar committed Nov 19, 2024
1 parent 91442ba commit 80558d1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion chirp/src/chirp_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ static const char *safe_username = 0;
static int sim_latency = 0;
static int stall_timeout = 3600; /* one hour */
static time_t starttime;
static char *ticket_duration_limit = 0;

/* space_available() is a simple mechanism to ensure that a runaway client does
* not use up every last drop of disk space on a machine. This function
Expand Down Expand Up @@ -532,6 +533,22 @@ static INT64_T getvarstring (struct link *l, time_t stalltime, void *buffer, INT
}
}

static const char *impose_ticket_duration_limit(const char *duration_requested) {
if (!ticket_duration_limit) {
return duration_requested;
}

INT64_T requested = strtoul(duration_requested, NULL, 10);
INT64_T limit = strtoul(ticket_duration_limit, NULL, 10);

if (requested < limit) {
return duration_requested;
}

return ticket_duration_limit;
}


/* A note on integers:
*
* Various operating systems employ integers of different sizes for fields such
Expand Down Expand Up @@ -1261,7 +1278,7 @@ static void chirp_handler(struct link *l, const char *addr, const char *subject)
if ((length = getvarstring(l, stalltime, buffer, length, 0)) == -1)
goto failure;
char *newsubject = chararg1;
char *duration = chararg2;
const char *duration = impose_ticket_duration_limit(chararg2);
if(strcmp(newsubject, "self") == 0)
strcpy(newsubject, esubject);
if(strcmp(esubject, newsubject) != 0 && strcmp(esubject, chirp_super_user) != 0) { /* must be superuser to create a ticket for someone else */
Expand Down

0 comments on commit 80558d1

Please sign in to comment.