I want to delete some files and directories owned by root from another different user in HP-UX 10.20.
The list of files looks like:
(user test)
bash-2.03$ ls -alrt
total 20
-rw-r--r-- 1 root root 55 Aug 27 2003 _index_jsp_2.dat
-rw-r--r-- 1 root root 4100 Aug 27 2003 _index.class
drwxr-xr-x 3 root other 512 Jan 22 13:33 ..
drwxr-xr-x 2 root root 512 Mar 5 10:53 error_5F_pages
drwxr-xr-x 4 root other 512 Mar 5 10:54 .
drwxr-xr-x 5 root root 512 Apr 12 19:24 jsp
I have programmed and compiled a C source as root that executes a shell and have set the s-uid-gid bit in order to execute them with the efective user root.
The C source sais:
/***********************************************/
#include <stdio.h>
#include <unistd.h>
int main(){
char *env[]={"PATH=/bin:/usr/bin",NULL};
char prog[]="/appli/test/shtest";
if (access(prog,X_OK)){
fprintf(stderr,"ERROR: %s \n",prog);
return(1);
}
system(prog);
perror("test");
return(1);
}
/***********************************************/
The shell (/appli/test/shtest):
rm -r /appli/test/www/*
-rw-r--r-- 1 root other 43 Apr 12 11:25 makefile
-rw-r--r-- 1 root other 328 Apr 12 11:47 test.c
-rwsrwsrwt 1 root other 6808 Apr 12 11:51 test2
-rwxrwxrwx 1 root other 74 Apr 13 08:39 shtest
The binary (test2) tries to execute shtest which is the shell that tries to remove these files.
When I execute it as "test" the system message says:
rm: /appli/test/www/_index.class: override protection 644 (yes/no)? yes
rm: /appli/test/www/_index.class not removed: Permission denied
The problem is that the directory where the list of files are stored is owned by root and the user isn't allowed for writing in it:
drwxr-xr-x 4 root other 512 Mar 5 10:54 www
It's not possible to change this permissons because they are automatically generated and we don't want to use a cron task which changes these permissons because there are thousands of files of this kind that we want to delete.
Do you know if I can remove these files and directories with a non-root (nor system...) user?
Thanks in advance