Line data Source code
1 : /* 2 : Wrapper for smbspool to test Device URI in argv[0] 3 : 4 : Copyright (C) Bryan Mason 2019 5 : 6 : This program is free software; you can redistribute it and/or modify 7 : it under the terms of the GNU General Public License as published by 8 : the Free Software Foundation; either version 3 of the License, or 9 : (at your option) any later version. 10 : 11 : This program is distributed in the hope that it will be useful, 12 : but WITHOUT ANY WARRANTY; without even the implied warranty of 13 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 : GNU General Public License for more details. 15 : 16 : You should have received a copy of the GNU General Public License 17 : along with this program. If not, see <http://www.gnu.org/licenses/>. 18 : */ 19 : 20 : #include <unistd.h> 21 : #include <stdlib.h> 22 : #include <errno.h> 23 : 24 : /* 25 : * Before calling a backend like smbspool, CUPS will set argv[0] to 26 : * the Device URI. This program wraps a program like smbspool and 27 : * sets argv[0] to the device URI before exec()ing the actual backend 28 : * program. 29 : */ 30 : 31 4 : int main(int argc, char *argv[], char *envp[]) 32 : { 33 : char **new_argv; 34 : char *exec_path; 35 : int a; 36 : int rv; 37 : /* 38 : * Expected parameters: 39 : * 40 : * smbspool_argv_wrapper smbspool uri job user title copies opts file(s) 41 : * argv[0] 1 2 3 4 5 6 7 8 42 : * 43 : */ 44 : /* Allocate memory for the new arguments (exit on failure). */ 45 4 : new_argv = calloc(argc, sizeof(char *)); 46 4 : if (new_argv == 0) { 47 0 : exit(ENOMEM); 48 : } 49 : 50 : /* Save the path to the smbspool executable */ 51 4 : exec_path = argv[1]; 52 : 53 : /* 54 : * Shift the rest of the args so smbspool is called with: 55 : * 56 : * uri job user title copies opts file(s) 57 : * argv[0] 1 2 3 4 5 6 58 : */ 59 : 60 30 : for (a = 2; a < argc; a++) { 61 26 : new_argv[a-2] = argv[a]; 62 : } 63 : 64 : /* Execute smbspool with new arguments */ 65 4 : rv = execve(exec_path, new_argv, envp); 66 4 : if (rv == -1) { 67 0 : exit(errno); 68 : } 69 : 70 : /* Avoid compiler error/warning */ 71 4 : return 0; 72 : }