11011110000
MIS
I am not an experienced C programmer by any means, but I need to allow a user to change permissions and the owner on multiple files, and the only way I know how is the code below. Would someone show me a more efficient way? Thanks.
Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <ctype.h>
#include <strings.h>
main(int argc, char *argv[]) {
int uid;
char cmd[100];
char cmda[100];
char cmdb[100];
char cmdc[100];
char cmdd[100];
char cmde[100];
char cmdf[100];
char cmdg[100];
char cmdh[100];
uid = getuid();
if( uid = 273 ) {
setuid(0);
setgid(0);
sprintf(cmd,"chmod 444 /`uname -n`/u01/oracle/product/express634/olap/oes634/owa634/*.db\n");
system(cmd);
sprintf(cmda,"chown oracle /`uname -n`/u01/oracle/product/express634/olap/oes634/owa634/*.db\n");
system(cmda);
sprintf(cmdb,"chmod 444 /`uname -n`/u01/oracle/product/express634/olap/oes634/owa634/*.prep7\n");
system(cmdb);
sprintf(cmdc,"chown oracle /`uname -n`/u01/oracle/product/express634/olap/oes634/owa634/*.prep7\n");
system(cmdc);
sprintf(cmdd,"chmod 444 "chmod 444 /`uname -n`/u01/oracle/product/express634/olap/oes634/owp634/xwascode.db\n");
system(cmdd);
sprintf(cmde,"chown oracle /`uname -n`/u01/oracle/product/express634/olap/oes634/owp634/xwascode.db\n");
system(cmde);
sprintf(cmdf,"chmod 444 /`uname -n`/u01/oracle/product/express634/olap/oes634/service/oec634/XPDDCODE.DB\n");
system(cmdf);
sprintf(cmdg,"chown oracle /`uname -n`/u01/oracle/product/express634/olap/oes634/service/oec634/XPDDCODE.DB\n");
system(cmdg);
sprintf(cmdh,"chmod 444 /`uname -n`/u01/oracle/product/express634/olap/oes634/owa634/java/*\n");
system(cmdh);
else {
printf("\007You are not authorized to run this program. Your UID is %d.\n", uid);
printf("\007Exiting.\n");
exit(1);
}
}