/* ** vfsh.c - for the really random among us ** ** Copyright (c) 1999 Peter Eriksson ** ** Version: 1.0 ** ** This program is free software; you can redistribute it and/or ** modify it as you wish - as long as you don't claim that you wrote ** it. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include #include #include #include #include static char * shells[] = { "/bin/sh", "/bin/csh", "/bin/ksh", "/bin/tcsh", "/bin/bash", "/bin/zsh" "/usr/local/bin/tcsh", "/usr/local/bin/bash", "/usr/local/bin/zsh" }; int main(int argc, char *argv[]) { char shn[256]; int is_login = (argv[0] && argv[0][0] == '-'); char *shp, *cp; unsigned int attempt = 0; srand((unsigned int) time(NULL)); do { shp = shells[((unsigned int) rand()) % (sizeof(shells)/sizeof(shells[0]))]; cp = strrchr(shp, '/'); if (is_login) shn[0] = '-'; strcat(shn+is_login, cp ? cp+1 : shp); argv[0] = shn; execv(shp, argv); } while (errno == ENOENT && attempt++ < 16); fprintf(stderr, "vfsh: execv(\"%s\"): %s\n", shp, strerror(errno)); exit(1); }