Annotation of coherent/d/bin/uucheck/checkperms/hosts.c, revision 1.1

1.1     ! root        1: /* hosts.c - handles lists of uucp hosts.
        !             2:  * part of uucheck
        !             3:  */
        !             4: 
        !             5: #include <stdio.h>
        !             6: #include "checkperms.h"
        !             7: 
        !             8: struct hostname_struct {
        !             9:        char    *hostname;
        !            10:        struct hostname_struct  *next_hostname;
        !            11: };
        !            12: 
        !            13: typedef struct hostname_struct hostname_type;
        !            14: 
        !            15: static hostname_type *first_hostname = (hostname_type *) NULL;
        !            16: 
        !            17: char *
        !            18: first_host(command)
        !            19:        char *command;
        !            20: {
        !            21:        FILE *fp;
        !            22:        hostname_type *current_hostname; /* Linked list walker.  */
        !            23: 
        !            24:        /* Here is where we open Permissions and L.sys and extract a list
        !            25:          * of all the hosts we might talk to.  This list will be walked
        !            26:         * through by "next_host()".
        !            27:         */
        !            28: 
        !            29:        if ((fp = popen(command, "r")) == NULL) {
        !            30:                FATAL("Can not create list of host names.\n", NULL);
        !            31:        } /* if can not open pipe to uuname */
        !            32:        
        !            33:        /* Read all the output of uuname into out linked list.  */
        !            34: 
        !            35:        if (fgets(bigbuf, MAX_NAME + 1, fp) != NULL) {
        !            36:            bigbuf[strlen(bigbuf) - 1 ] = (char) NULL; /* Wipe out trailing nl.  */
        !            37:            /* Make space for the first entry.  */
        !            38:            first_hostname = (hostname_type *) malloc(sizeof(hostname_type));
        !            39:            /* Move up to the new entry.  */
        !            40:            current_hostname = first_hostname;
        !            41:            /* Copy the first hostname into the list.  */
        !            42:            copy_str(&current_hostname->hostname, bigbuf);
        !            43:            current_hostname->next_hostname = (hostname_type *) NULL;
        !            44:        } /* if (fgets(bigbuf, MAX_NAME + 1, fp) != NULL) */
        !            45:        
        !            46:        while (fgets(bigbuf, MAX_NAME + 1, fp) != NULL) {
        !            47:            bigbuf[strlen(bigbuf) - 1] = (char) NULL; /* Wipe out trailing nl.  */
        !            48:            /* Make space for the next entry.  */
        !            49:            current_hostname->next_hostname =
        !            50:                (hostname_type *) malloc(sizeof(hostname_type));
        !            51:            /* Move up to the new entry.  */
        !            52:            current_hostname = current_hostname->next_hostname;
        !            53:            /* Copy the next hostname into the list.  */
        !            54:            copy_str(&current_hostname->hostname, bigbuf);
        !            55:            current_hostname->next_hostname = (hostname_type *) NULL;
        !            56:        } /* while (fgets(bigbuf, MAX_NAME + 1, fp) != NULL) */
        !            57: 
        !            58:        /* Is this list only one entry long?  */
        !            59:        if (first_hostname->next_hostname != NULL ) {
        !            60:                last_host = FALSE;
        !            61:        } else {
        !            62:                last_host = TRUE;
        !            63:        }
        !            64:        return(first_hostname->hostname);
        !            65: } /* first_host() */
        !            66: 
        !            67: /* Destructively return the next host to be processed.  */
        !            68: char *
        !            69: next_host()
        !            70: {
        !            71:        hostname_type *tmp;
        !            72: 
        !            73:        if ( first_hostname != NULL ) {
        !            74:                free(first_hostname->hostname); /* Throw away the last name.  */
        !            75:                tmp=first_hostname;
        !            76:                first_hostname = first_hostname->next_hostname;
        !            77:                free(tmp); /* Throw away the structure it was stored in.  */
        !            78:                if (first_hostname->next_hostname == (hostname_type *) NULL) {
        !            79:                        last_host = TRUE; /* About to return the last host in the list.  */     
        !            80:                } /* if this is the last host  */
        !            81:                return(first_hostname->hostname);
        !            82:        } else {
        !            83:                return(NULL);
        !            84:        } /* if fist_hostname != NULL (no hosts left) */
        !            85:        FATAL("Unreachable statement in next_host() reached.\n", NULL);
        !            86: } /* next_host() */

unix.superglobalmegacorp.com

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