#include #include #include #include #include #include int main(int argc, char **argv) { struct rlimit lim; /* Make sure we are called with enought arguments */ if (argc < 2) { setuid(getuid()); fprintf(stderr,"Usage: %s limit program [arguments...]\n" " Sets the RLIM_NOFILES limit and starts the supplied" " program\n", argv[0]); exit(1); } /* Set the new MAX open files limit */ lim.rlim_cur = lim.rlim_max = atoi(argv[1]); if (setrlimit(RLIMIT_NOFILE, &lim) != 0) { setuid(getuid()); perror("setrlimit"); exit(1); } /* Drop SUID privilegies */ setuid(getuid()); /* Start the wanted program */ execvp(argv[2],argv+2); perror("exec failed"); exit(1); }