pkexec: improve pkexec authentication message
Instead of the program
variable, output the command_line
.
If is the length of a command_line
bigger than 80 characters, output is: "{first 38 chars from the CL} ... {last 42 chars from the CL}"
Commented code:
if (strlen(command_line) > 80 ) {
char buff[80];
// The memset() function fills the first n bytes of the memory area
// pointed to by s with the constant byte c.
memset(buff, 0, strlen(buff));
// declares a char array of size 6 and initializes it with the characters ' ', '.', '.', '.', ' ' and '\0'
char delim[] = " ... ";
// char *strncpy(char *dest, const char *src, size_t n);
// Warning: If there is no null byte among the
// first n bytes of src, the string placed in dest will not be null-
// terminated.
// copy the first 37 chars from CL into the buff
strncpy(buff, command_line, 38);
// copy the delimiter into the buff
strncpy(buff + 38, delim, 5);
// copy the last 38 chars from CL into the buff
strncpy(buff + 43, command_line +
strlen(command_line) - 37,
38);
// copy the buff into the command_line
strncpy(command_line, buff, 80);
// The memset() function fills the first n bytes of the memory area
// pointed to by s with the constant byte c.
memset(command_line + 80, 0, strlen(command_line) - 80);
}