| 75 | */ |
| 76 | |
| 77 | _cups_fc_result_t /* O - Check result */ |
| 78 | _cupsFileCheck( |
| 79 | const char *filename, /* I - Filename to check */ |
| 80 | _cups_fc_filetype_t filetype, /* I - Type of file checks? */ |
| 81 | int dorootchecks, /* I - Check for root permissions? */ |
| 82 | _cups_fc_func_t cb, /* I - Callback function */ |
| 83 | void *context) /* I - Context pointer for callback */ |
| 84 | |
| 85 | { |
| 86 | struct stat fileinfo; /* File information */ |
| 87 | char message[1024], /* Message string */ |
| 88 | temp[1024], /* Parent directory filename */ |
| 89 | *ptr; /* Pointer into parent directory */ |
| 90 | _cups_fc_result_t result; /* Check result */ |
| 91 | |
| 92 | |
| 93 | /* |
| 94 | * Does the filename contain a relative path ("../")? |
| 95 | */ |
| 96 | |
| 97 | if (strstr(filename, "../")) |
| 98 | { |
| 99 | /* |
| 100 | * Yes, fail it! |
| 101 | */ |
| 102 | |
| 103 | result = _CUPS_FILE_CHECK_RELATIVE_PATH; |
| 104 | goto finishup; |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * Does the program even exist and is it accessible? |
| 109 | */ |
| 110 | |
| 111 | if (stat(filename, &fileinfo)) |
| 112 | { |
| 113 | /* |
| 114 | * Nope... |
| 115 | */ |
| 116 | |
| 117 | result = _CUPS_FILE_CHECK_MISSING; |
| 118 | goto finishup; |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * Check the execute bit... |
| 123 | */ |
| 124 | |
| 125 | result = _CUPS_FILE_CHECK_OK; |
| 126 | |
| 127 | if (filetype == _CUPS_FILE_CHECK_DIRECTORY) |
| 128 | { |
| 129 | if (!S_ISDIR(fileinfo.st_mode)) |
| 130 | result = _CUPS_FILE_CHECK_WRONG_TYPE; |
| 131 | } |
| 132 | else if (!S_ISREG(fileinfo.st_mode)) |
| 133 | { |
| 134 | result = _CUPS_FILE_CHECK_WRONG_TYPE; |
no test coverage detected