1837885 Members
3074 Online
110122 Solutions
New Discussion

script question

 
Madanagopalan S
Frequent Advisor

script question

1. Writing script to cancel print jobs. This script will cancel all the users print jobs.
this will be executed by the particular user. Can Anyone through how can I
achieve this. I tried suid option (chmod 4711 file). still have problem?

2. While running a script, user could not able to use ctrl+c or any other command
to get unix prompt. If any interruption occurs, it should go back to previous menu.

Pls help me.
let Start to create peaceful and happy world
9 REPLIES 9
Andreas Voss
Honored Contributor

Re: script question

Hi,

when using suid/sgid on shell scripts you must have at the first line (example posix-shell):
#!/sbin/sh
To prevent exiting the script by CTRL-C do:
trap "echo break" 2
(make sure you have an input option to leave the script)

Regards
Madanagopalan S
Frequent Advisor

Re: script question

I tried the same. but its still saying " must have root capability to use this option" for cancel command. How can I do it for C program.
let Start to create peaceful and happy world
James R. Ferguson
Acclaimed Contributor

Re: script question

Hi:

One way to avoid the suid problem altogether in this case is to (re)create your print queues allowing CANCEL by anyone. There's a check-box when you setup printers in SAM to specify this. The -orc option of 'lpadmin' controls this ability.

...JRF...

Madanagopalan S
Frequent Advisor

Re: script question

I can't recreate the print queues since nearly more than 20 queues are there
and the machine is in production now.
let Start to create peaceful and happy world
Andreas Voss
Honored Contributor

Re: script question

Hi,

here an example c source:
main(argc, argv)
int argc;
char **argv;
{
setuid(9);
setgid(7);
execvp("/usr/bin/cancel", argv);
}
Compile ie:
cc mycancel.c -o /usr/contrib/bin/mycancel
chown lp:lp /usr/contrib/bin/mycancel
chmod ug+s /usr/contrib/bin/mycancel

Regards
Madanagopalan S
Frequent Advisor

Re: script question

Andreas voss,

I can't able to use the '-e' option. other thing is working fine. What could
be the problem
let Start to create peaceful and happy world
Andreas Voss
Honored Contributor

Re: script question

Hi,

so you have to set root capabilties (but i think this could be a security risk):
main(argc, argv)
int argc;
char **argv;
{
setuid(0); setgid(3);
execvp("/usr/bin/cancel", argv);
}
Compile ie:
cc mycancel.c -o /usr/contrib/bin/mycancel
chown root:sys /usr/contrib/bin/mycancel
chmod ug+s /usr/contrib/bin/mycancel

Regards
Alan Riggs
Honored Contributor

Re: script question

Am I missing something? Isn't this exactly what the command "cancel -a" is designed to do? A user always has the ability to cancel his own print jobs, and teh -a flag tells cancel to stop all jobs to any printer owned by the login user.
Carlos Fernandez Riera
Honored Contributor

Re: script question


If -orc option run sucesfully to you, reacreate printers is not a great problem.

Fisrt, do a tar cvf /tmp/printers /etc/lp/interface

Write a script to remove and recreate printers based on lpstat -v ( printer and device ), for each printer you must generate commands:

lpadmin -x.....
lpadmin -d xxxxx -mdumb printer
enable printer
accept printer


As final step recover printer interfaces ( tar xvf /tmp/printers). Interface files are scripts, so dumb printer will be recover with actual script.

Create a printer for test, and when you procedure run ok, apply to all printers.




CNTRL-C.


If you dont like users break your shell do:
trap ' ' 2.
This will avoid treatement of INTR signal.



unsupported