Annotation of coherent/d/etc/SYSVcron/src/crontab.c, revision 1.1

1.1     ! root        1: /* 
        !             2:  *     The information contained herein is a trade secret of Mark Williams
        !             3:  *     Company, and  is confidential information.  It is provided  under a
        !             4:  *     license agreement,  and may be  copied or disclosed  only under the
        !             5:  *     terms of  that agreement.  Any  reproduction or disclosure  of this
        !             6:  *     material without the express written authorization of Mark Williams
        !             7:  *     Company or persuant to the license agreement is unlawful.
        !             8:  *
        !             9:  *     An unpublished work by Mark Williams Company, Chicago.
        !            10:  *     All rights reserved.
        !            11:  */
        !            12: 
        !            13: /*
        !            14:  * crontab.c
        !            15:  *
        !            16:  * Emulation of the SV crontab command.
        !            17:  * 
        !            18:  * The next table shows conditions when user is allowed to use crontab.
        !            19:  *    
        !            20:  *     \ deny   exist           exist          exist           doesn't
        !            21:  *      \      is user         no user         but empty        exist
        !            22:  * allow \
        !            23:  * _______\________________________________________________________________
        !            24:  *  exist  |      
        !            25:  * is user |        Y             Y               Y               Y
        !            26:  * ------------------------------------------------------------------------
        !            27:  *  exist  |
        !            28:  * no user |        N              N               N               N       
        !            29:  * ------------------------------------------------------------------------
        !            30:  *  doesn't|
        !            31:  *   exist |        N              Y               Y               N
        !            32:  *
        !            33:  * Where deny means the file /usr/lib/cron/cron.deny, and allow is
        !            34:  * the file /usr/lib/cron/cron.allow
        !            35:  * This table is not valid for user root hwich can always use crontab.
        !            36:  *
        !            37:  * $ 12-06-1991 vlad (Vladimir Smelyansky)
        !            38:  *
        !            39:  */
        !            40: #include       <pwd.h>
        !            41: #include       <errno.h>
        !            42: #include       <stdio.h>
        !            43: #include       "cron.h"
        !            44: 
        !            45: extern int     iAllow();               /* Check permissions to use crontab */
        !            46: extern void    vDelete();              /* Delete user crontable */
        !            47: extern void    vList();                /* List user crontable */
        !            48: extern void    vMailDisable();         /* Disable the mail messages */
        !            49: extern void    vMailEnable();          /* Enable the mail messages */
        !            50: extern void    vReplace();             /* Replace user crontable */
        !            51: 
        !            52: extern char    *pcFileName;            /* User crontab */
        !            53: 
        !            54: char   acRealUser[MAX_UNAME];          /* Real user name */
        !            55: char   *pcUserName;                    /* User name from a command line */
        !            56: FILE   *pfNewTab;
        !            57: int    lFlag = FALSE,                  /* List crontab */
        !            58:        rFlag = FALSE,                  /* Delete crontab */
        !            59:        fFlag = FALSE,                  /* Replace crontab */
        !            60:        uFlag = FALSE,                  /* User name */
        !            61:        mFlag = FALSE,                  /* Mail enable/disable */
        !            62:        ldrFlag = FALSE;
        !            63: 
        !            64: main(argc, argv)
        !            65: int    argc;
        !            66: char   *argv[];
        !            67: {
        !            68:        int             iChar;
        !            69:        extern int      optind;
        !            70:        extern char     *optarg;
        !            71: 
        !            72:        /* Check if user allowed to use the crontab. 
        !            73:         * NOTICE: iAllow finds real user name (acRealUser).
        !            74:         */
        !            75:        if (iAllow() != TRUE) {
        !            76:                fprintf(stderr, "Sorry, you are not authorized to use cron\n");
        !            77:                exit(1);
        !            78:        }
        !            79: 
        !            80:        /* Ok, we have permissions to execute it.
        !            81:        */
        !            82:        while((iChar = getopt(argc, argv, "u:lrf:m:")) != EOF) {
        !            83:                switch(iChar) {
        !            84:                case 'l':               /* List crontab */
        !            85:                        if (ldrFlag)
        !            86:                                usage();
        !            87:                        lFlag = ldrFlag = TRUE;
        !            88:                        break;
        !            89:                case 'r':               /* Remove crontab */
        !            90:                        if (ldrFlag)
        !            91:                                usage();
        !            92:                        rFlag = ldrFlag = TRUE;
        !            93:                        break;
        !            94:                case 'f':               /* Replace crontab */
        !            95:                        if (ldrFlag)
        !            96:                                usage();
        !            97:                        fFlag = ldrFlag = TRUE;
        !            98:                        pcFileName = optarg;
        !            99:                        Dprint("main: file is %s\n", pcFileName);
        !           100:                        break;
        !           101:                case 'u':               /* User name */
        !           102:                        if (strcmp(acRealUser, optarg)) {
        !           103:                                if (strcmp(acRealUser, "root")) {
        !           104:                                        fprintf(stderr, 
        !           105: "Sorry, you are not autorized edit '%s' crontab\n", pcUserName);
        !           106:                                        exit(1);
        !           107:                                }
        !           108:                                strncpy(acRealUser, optarg, MAX_UNAME);
        !           109:                        }
        !           110:                        break;
        !           111:                case 'm':               /* Enable disable mail */
        !           112:                        mFlag = TRUE;
        !           113:                        switch(optarg[0]) {
        !           114:                        case 'e':
        !           115:                                Dprint("crontab: mail enable. %s\n", optarg);
        !           116:                                vMailEnable();
        !           117:                                break;
        !           118:                        case 'd':
        !           119:                                Dprint("crontab: mail disable. %s\n", optarg);
        !           120:                                vMailDisable();
        !           121:                                break;
        !           122:                        default:
        !           123:                                usage();
        !           124:                        }
        !           125:                        break;
        !           126:                case '?':
        !           127:                default:
        !           128:                        usage();
        !           129:                }
        !           130:        }
        !           131: 
        !           132:        /* At least one option should be given.
        !           133:        */
        !           134:        if (ldrFlag == FALSE && mFlag == FALSE) 
        !           135:                usage();
        !           136: 
        !           137:        if (lFlag) {    /* List user crontab */
        !           138:                vList();
        !           139:                exit(0);
        !           140:        }
        !           141:        if (fFlag) {    /* Replace user crontab */
        !           142:                Dprint("main: Case replace. User %s\n", acRealUser);
        !           143:                vReplace();
        !           144:                exit(0);
        !           145:        }
        !           146:        if (rFlag) {    /* Remove user crontab */
        !           147:                vDelete();
        !           148:                exit(0);
        !           149:        }
        !           150:        exit(1);
        !           151: }
        !           152: 
        !           153: usage()
        !           154: {
        !           155:        fprintf(stderr, "usage:  crontab [-u user_name] ...\n");
        !           156:        fprintf(stderr, "\t\t-l                       list user's crontab\n");
        !           157:        fprintf(stderr, "\t\t-r                       remove user's crontab\n");
        !           158:        fprintf(stderr, "\t\t-f file_name             replace user's crontab\n");
        !           159:        fprintf(stderr, "\t\t-m e[nable]/d[isable]    enable/disable mail\n");
        !           160:        exit(1);
        !           161: }
        !           162: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.