Example #1
0
int authorized(char *address)
{
struct drm_names *name;
char buffer[DRM_BUFLEN], *token[8];
int i, status, lineno, ntoken;
static FILE *fp = (FILE *) NULL;
static char *fid = "authorized";

    name = drm_names();
    if (fp == (FILE *) NULL) fp = fopen(name->path.auth, "r");
    if (fp == (FILE *) NULL) return FALSE;
    rewind(fp);

    lineno = 0;

    while (GETLINE == 0) {
        ntoken = util_parse(buffer, token, " ", 8, 0);
        for (i = 0; i < ntoken; i++) {
            if (strcasecmp(token[i], address) == 0) return TRUE;
        }
    }

    util_log(1, "%s is not authorized for dial-up access", address);

    return FALSE;
}
Example #2
0
static void command_parse(char* str)
{
    char* array[8] = {0};
    int i = 0, x = 0;

  if (strlen(str) < 3) /* if user simply pressed enter, ignore */
	 return;

    str += 2; /* '] ' */
    i = util_parse(str, array, " ,", 8, '"');

    while(gDispatch[x].function) {
        if(array[0]) {
            if(strcmp(gDispatch[x].name, array[0]) == 0) {
                if(gDispatch[x].function) {
                    i--;
                    gDispatch[x].function(i, array);
                    return;
                }
            }
        }
        x++;
    }

    printf("\x1b[01m" "?SYNTAX ERROR" "\x1b[00m" "\n");

    return;
}
REAL64 util_attodt(CHAR *string)
{
CHAR copy[COPYBUFLEN];
CHAR *token[6];
INT16 errors, ntoken, yr, da, hr, mn, sc, ms;

/*  Check for special case ("present")  */

    if (strcasecmp(string, "present") == 0) return (double) 2147483647;

/*  Parse (copy of) string  */

    memcpy((void *) copy, (void *) string, (size_t) COPYBUFLEN-1);
    copy[COPYBUFLEN] = 0;

    ntoken = util_parse(copy, token, "-/.:(),;", 6, 0);

    yr = hr = mn = sc = ms = 0; da = 1;

/* Decode the various pieces */

    switch (ntoken) {

      case 6:
        ms = (INT16) atoi(token[5]);
      case 5:
        sc = (INT16) atoi(token[4]);
      case 4:
        mn = (INT16) atoi(token[3]);
      case 3:
        hr = (INT16) atoi(token[2]);
      case 2:
        da = (INT16) atoi(token[1]);
      case 1:
        yr = (INT16) atoi(token[0]) + ((strlen(token[0]) == 2) ? 1900 : 0);
        break;
      default:
        errno = EINVAL;
        return -1.0;
    }

    errors = 0;
    if (yr < 1970)          ++errors;
    if (da < 1 || da > 366) ++errors;
    if (hr < 0 || hr >  23) ++errors;
    if (mn < 0 || mn >  59) ++errors;
    if (sc < 0 || sc >  59) ++errors;
    if (ms < 0 || ms > 999) ++errors;
    
    if (errors) {
        errno = EINVAL;
        return -2.0;
    }

    return util_ydhmsmtod(yr, da, hr, mn, sc, ms);

}
int util_cfgpair(FILE *fp, int *lineno, char **identifier, char **value)
{
static char buffer[LOCAL_BUFLEN];
static char *token[MAXTOKENS];
int status, ntoken;

    status = util_getline(fp, buffer, LOCAL_BUFLEN, COMMENT, lineno);
    if (status != 0) return status;

    ntoken = util_parse(buffer, token, DELIMITERS, MAXTOKENS, QUOTE);
    if (ntoken != 2) {
        errno = EINVAL;
        return -1;
    }
    
    *identifier = token[0];
    *value      = token[1];

    return 0;
}
Example #5
0
int isp_readcnf(char *fname, struct isp_dascnf *cnf)
{
FILE *fp;
int i, j, status, lineno = 0, ntoken, errors;
char *token[MAX_TOKEN];
char buffer[BUFLEN];
static char *fid = "isp_readcnf";

    for (i = 0; i < DAS_MAXSTREAM; i++) cnf->stream[i].active = 0;
    cnf->detect.nchan = 0;

    if ((fp = fopen(fname, "r")) == (FILE *) NULL) {
        util_log(1, "%s: fopen: %s: %s", fid, fname, syserrmsg(errno));
        return -1;
    }

    errors = 0;
    while ((status = util_getline(fp, buffer, BUFLEN, '#', &lineno)) == 0) {

        ntoken = util_parse(buffer, token, DELIMITERS, MAX_TOKEN, 0);

        if (strcasecmp(token[0], "stream") == 0) {
            if (ntoken != 6) {
                util_log(1, "%s: syntax error near %s line %d",
                    fid, fname, lineno
                );
                ++errors;
            }
            i = atoi(token[1]);
            if (i < 0 || i >= DAS_MAXSTREAM) {
                util_log(1, "%s: illegal stream code, %s line %d",
                    fid, fname, lineno
                );
                fclose(fp);
                return -2;
            }
            if (strcasecmp(token[2], "y") == 0) {
                cnf->stream[i].active = 1;
            } else if (strcasecmp(token[2], "n") == 0) {
                cnf->stream[i].active = 0;
            } else {
                util_log(1, "%s: illegal on/off flag, %s line %d",
                    fid, fname, lineno
                );
                ++errors;
            }
            if (cnf->stream[i].active) {
                cnf->stream[i].channel = atoi(token[3]);
                if (
                    cnf->stream[i].channel < 0 ||
                       cnf->stream[i].channel > DAS_MAXCHAN
                ) {
                    util_log(1, "%s: illegal channel, %s line %d",
                        fid, fname, lineno
                    );
                    ++errors;
                }
                cnf->stream[i].filter  = atoi(token[4]);
                if (strcasecmp(token[5], "c") == 0) {
                    cnf->stream[i].mode = 0;
                } else if (strcasecmp(token[5], "t") == 0) {
                    cnf->stream[i].mode = 1;
                } else {
                    util_log(1, "%s: illegal mode flag, %s line %d",
                        fid, fname, lineno
                    );
                    ++errors;
                }
            } else {
                cnf->stream[i].channel = -1;
                cnf->stream[i].filter  = -1;
                cnf->stream[i].mode    =  0;
            }

        } else if (strcasecmp(token[0], "Chans") == 0) {
            cnf->detect.bitmap = 0;
            cnf->detect.nchan = ntoken - 1;
            for (i = 0; i < cnf->detect.nchan; i++) {
                cnf->detect.chan[i] = atoi(token[i+1]);
                if (
                    cnf->detect.chan[i] < 0 ||
                    cnf->detect.chan[i] > DAS_MAXCHAN
                ) {
                    util_log(1, "%s: illegal detector chan, %s line %d",
                        fid, fname, lineno
                    );
                    ++errors;
                } else {
                    cnf->detect.bitmap |= 1 << cnf->detect.chan[i];
                }
            }

        } else if (strcasecmp(token[0], "Key") == 0) {
            if (ntoken != 2) {
                util_log(1, "%s: syntax error near %s line %d",
                    fid, fname, lineno
                );
                ++errors;
            }
            cnf->detect.key = atoi(token[1]);

        } else if (strcasecmp(token[0], "STA") == 0) {
            if (ntoken != 2) {
                util_log(1, "%s: syntax error near %s line %d",
                    fid, fname, lineno
                );
                ++errors;
            }
            cnf->detect.sta = atoi(token[1]);

        } else if (strcasecmp(token[0], "LTA") == 0) {
            if (ntoken != 2) {
                util_log(1, "%s: syntax error near %s line %d",
                    fid, fname, lineno
                );
                ++errors;
            }
            cnf->detect.lta = atoi(token[1]);
        } else if (strcasecmp(token[0], "Thresh") == 0) {
            if (ntoken != 2) {
                util_log(1, "%s: syntax error near %s line %d",
                    fid, fname, lineno
                );
                ++errors;
            }
            cnf->detect.thresh = (int) (10000.0 / atof(token[1]));

        } else if (strcasecmp(token[0], "Voters") == 0) {
            if (ntoken != 2) {
                util_log(1, "%s: syntax error near %s line %d",
                    fid, fname, lineno
                );
                ++errors;
            }
            cnf->detect.voters = atoi(token[1]);

        } else if (strcasecmp(token[0], "MaxTrig") == 0) {
            if (ntoken != 2) {
                util_log(1, "%s: syntax error near %s line %d",
                    fid, fname, lineno
                );
                ++errors;
            }
            cnf->detect.maxtrig = atol(token[1]);
        } else if (strcasecmp(token[0], "Pre-event") == 0) {
            if (ntoken != 2) {
                util_log(1, "%s: syntax error near %s line %d",
                    fid, fname, lineno
                );
                ++errors;
            }
            cnf->detect.preevent = atoi(token[1]);

        } else {
            util_log(1, "%s: syntax error near %s line %d",
                fid, fname, lineno
            );
            util_log(1, "%s: unrecognized identifer `%s'\n",
                fid, token[0]
            );
            ++errors;
        }
    }

    fclose(fp);
    cnf->flag = ISP_DASCNF_SET;
    return errors;
}
Example #6
0
BOOL ispLoadRunParam(char *path, char *sta, ISP_PARAMS *paramptr, ISP_SERVER *server)
{
BOOL first = TRUE;
BOOL ok;
FILE *fp;
int i, j, status, lineno = 0, ntoken, errors;
char *token[MAX_TOKEN];
char buffer[BUFLEN];
ISP_PARAMS unused, *params;
static ISP_IBOOT default_iboot = DEFAULT_ISP_IBOOT;
static char *fid = "load_param";

    if (paramptr != NULL) {
        params = paramptr;
    } else {
        params = &unused;
    }

/* Load default parameters */

    strcpy(params->port, DEFAULT_ISP_INPUT);
    strcpy(params->odev, DEFAULT_ISP_OUTPUT);

    params->ibaud         = DEFAULT_ISP_IBAUD;
    params->obaud         = DEFAULT_ISP_OBAUD;
    params->mtu           = DEFAULT_ISP_MTU;
    params->delay         = DEFAULT_ISP_DELAY;
    params->statint       = DEFAULT_ISP_STATINT;
    params->ttyto         = DEFAULT_ISP_TTYTO;
    params->nodatato      = DEFAULT_ISP_NODATATO;
    params->iddatato      = DEFAULT_ISP_IDDATATO;

    params->san.addr[0]   = 0;
    params->san.port.data = DEFAULT_ISP_SAN_DATA_PORT;
    params->san.port.cmnd = DEFAULT_ISP_SAN_CMND_PORT;
    params->san.timeout   = DEFAULT_ISP_SAN_TIMEOUT;
    params->san.sohint    = DEFAULT_ISP_SAN_SOHINT;

    params->rawq          = DEFAULT_ISP_RAWQ;
    params->cmdq          = DEFAULT_ISP_CMDQ;
    params->barq          = DEFAULT_ISP_BARQ;
    params->dpmq          = DEFAULT_ISP_DPMQ;

    params->bfact         = DEFAULT_ISP_BFACT;
    params->obuf          = DEFAULT_ISP_OBUF;
    params->numobuf       = DEFAULT_ISP_NUMOBUF;

    params->savedasstats  = 0;
    params->overwrite     = 0;
    params->nrts          = DEFAULT_ISP_NRTS;
    params->inject        = DEFAULT_ISP_INJECT;

    params->baro.enabled  = 0;
    params->dpm.enabled   = 0;
    params->clock.enabled = 0;

    params->flags         = DEFAULT_ISP_IDA_FLAGS;

    params->rt593.correct = DEFAULT_ISP_RT593;
    params->rt593.present = (params->rt593.correct) ? TRUE : FALSE;

    params->iboot         = default_iboot;

    server->sd         = -1;
    server->port       = DEFAULT_ISP_TCPPORT;
    server->to         = DEFAULT_ISP_SOCKETTO;
    server->maxclients = DEFAULT_ISP_MAXCLIENTS;

/* Override with contents of configuration file */

    if ((fp = fopen(path, "r")) == NULL) {
        fprintf(stderr, "%s: fopen", fid);
        perror(path);
        return FALSE;
    }

    while ((status = util_getline(fp, buffer, BUFLEN, '#', &lineno)) == 0) {
        ntoken = util_parse(buffer, token, DELIMITERS, MAX_TOKEN, 0);

    /* Check for SAN flag as first non-comment line */

        if (first) {
            if (ntoken == 2 && strcasecmp(token[0], "Digitizer") == 0) {
                params->digitizer = ISP_SAN;
                params->pktrev    = DEFAULT_ISP_SAN_PKTREV;
            } else {
                params->digitizer = ISP_DAS;
                params->pktrev    = DEFAULT_ISP_DAS_PKTREV;
            }
            first = FALSE;
            continue;
        }

    /* barometer, dpm, clock and iboot lines do not use 
     * the simple a = b form... check for these
     */

        if (ntoken != NUM_TOKEN) {
            if (strcasecmp(token[0], "baro") == 0) {
                ok = LoadBarometerParams(ntoken, token, params);
            } else if (strcasecmp(token[0], "dpm") == 0) {
                ok = LoadDPMParams(ntoken, token, params);
            } else if (strcasecmp(token[0], "clock") == 0) {
                ok = LoadClockParams(ntoken, token, params);
            } else if (strcasecmp(token[0], "iboot") == 0) {
                ok = LoadIbootParams(ntoken, token, params);
            }
            if (ok) continue;
            fprintf(stderr, "%s: syntax error near `%s' line %d\n",
                fid, path, lineno
            );
            fclose(fp);
            return FALSE;
        }

        if (strcasecmp(token[0], "port") == 0) {
            strncpy(params->port, token[1], ISP_DEVNAMLEN);
            params->port[ISP_DEVNAMLEN] = 0;
        } else if (strcasecmp(token[0], "ibaud") == 0) {
            params->ibaud = atol(token[1]);
        } else if (strcasecmp(token[0], "obaud") == 0) {
            params->obaud = atol(token[1]);
        } else if (strcasecmp(token[0], "mtu") == 0) {
            params->mtu = atol(token[1]);
        } else if (strcasecmp(token[0], "delay") == 0) {
            params->delay = atol(token[1]);
        } else if (strcasecmp(token[0], "pktrev") == 0) {
            params->pktrev = atoi(token[1]);
        } else if (strcasecmp(token[0], "statint") == 0) {
            params->statint = atol(token[1]);
        } else if (strcasecmp(token[0], "ttyto") == 0) {
            params->ttyto = atol(token[1]);
        } else if (strcasecmp(token[0], "nodatato") == 0) {
            params->nodatato = atol(token[1]);
        } else if (strcasecmp(token[0], "iddatato") == 0) {
            params->iddatato = atol(token[1]);

        } else if (strcasecmp(token[0], "rawq") == 0) {
            params->rawq = atol(token[1]);
        } else if (strcasecmp(token[0], "cmdq") == 0) {
            params->cmdq = atol(token[1]);
        } else if (strcasecmp(token[0], "barq") == 0) {
            params->barq = atol(token[1]);
        } else if (strcasecmp(token[0], "dpmq") == 0) {
            params->dpmq = atol(token[1]);
        } else if (strcasecmp(token[0], "rt593") == 0) {
            params->rt593.correct= atoi(token[1]);
            params->rt593.present = TRUE;

        } else if (strcasecmp(token[0], "output") == 0) {
            strncpy(params->odev, token[1], ISP_DEVNAMLEN);
            params->odev[ISP_DEVNAMLEN] = 0;
        } else if (strcasecmp(token[0], "bfact") == 0) {
            params->bfact = atol(token[1]);
        } else if (strcasecmp(token[0], "obuf") == 0) {
            params->obuf = atol(token[1]);
        } else if (strcasecmp(token[0], "numobuf") == 0) {
            params->numobuf = atol(token[1]);
        } else if (strcasecmp(token[0], "savedasstats") == 0) {
            params->savedasstats = atol(token[1]);
        } else if (strcasecmp(token[0], "nrts") == 0) {
            params->nrts = atoi(token[1]);
        } else if (strcasecmp(token[0], "inject") == 0) {
            params->inject = atoi(token[1]);

        } else if (strcasecmp(token[0], "dbdir") == 0 || (strcasecmp(token[0], "db") == 0)) {
            ; /* ignore db entries in run file */

        } else if (strcasecmp(token[0], "dbformat") == 0) {
            ; /* ignore db entries in run file */

        } else if (strcasecmp(token[0], "socketto") == 0) {
            server->to = atol(token[1]);

        } else if (strcasecmp(token[0], "tcpport") == 0) {
            server->port = atol(token[1]);

        } else if (strcasecmp(token[0], "maxclients") == 0) {
            server->maxclients = atol(token[1]);

        } else if (strcasecmp(token[0], "SANaddr") == 0) {
            memcpy(params->san.addr, token[1], ISP_ADDRNAMLEN);
            params->san.addr[ISP_ADDRNAMLEN] = 0;
            
        } else if (strcasecmp(token[0], "DataPort") == 0) {
            params->san.port.data = atoi(token[1]);

        } else if (strcasecmp(token[0], "CmndPort") == 0) {
            params->san.port.cmnd = atoi(token[1]);

        } else if (strcasecmp(token[0], "TimeOut") == 0) {
            params->san.timeout = atoi(token[1]);

        } else if (strcasecmp(token[0], "SohInterval") == 0) {
            params->san.sohint = atoi(token[1]);

        } else if (strcasecmp(token[0], "Flags") == 0) {
            params->flags = (UINT32) atoi(token[1]);

        } else {
            fprintf(stderr, "%s: syntax error near line %d of `%s'\n",
                fid, lineno, path
            );
            fprintf(stderr, "%s: unrecognized identifer `%s'\n",
                fid, token[0]
            );
            fclose(fp);
            return FALSE;
        }
    }
    fclose(fp);

    if (params == &unused) return TRUE;

    params->ida = idaCreateHandle(util_lcase(sta), params->pktrev, NULL, params->glob.db, NULL, params->flags);
    return CheckParam(sta, params, server, path);
}
Example #7
0
BOOL reftek_sc(struct reftek_sc *dest, UINT8 *src)
{
REAL32 value, factor;
CHAR temp[16], *token[2];
UINT8 *off, *ptr;
UINT16 i, ndx;
INT32 ntoken;

/* Load the common header */

    reftek_com(src, &dest->exp, &dest->unit, &dest->seqno, &dest->tstamp);

/* Load the record specific parts */

    dest->nchan = 0;
    for (i = 0; i < 5; i++) {
        off = src + 202 + (i * 146);

        ptr = off + 0;
        memcpy((void *) temp, (void *) ptr, (size_t) 2);
        temp[2] = 0;
        util_strtrm(temp);
        if (strlen(temp) > 0) {
            ndx = dest->nchan;
            dest->chan[ndx].num = atoi(temp);

            ptr = off + 2;
            strncpy((char *) dest->chan[ndx].name, (char *) ptr, 10);
            dest->chan[ndx].name[10] = 0;
            util_strtrm(dest->chan[ndx].name);

            ptr = off + 70;
            strncpy((char *) temp, (char *) ptr, 4);
            temp[4] = 0;
            util_strtrm(temp);
            dest->chan[ndx].gain = (REAL32) atof(temp);

            ptr = off + 74;
            strncpy((char *) dest->chan[ndx].model, (char *) ptr, 12);
            dest->chan[ndx].model[12] = 0;
            util_strtrm(dest->chan[ndx].model);

            ptr = off + 86;
            strncpy((char *) dest->chan[ndx].sn, (char *) ptr, 12);
            dest->chan[ndx].sn[12] = 0;
            util_strtrm(dest->chan[ndx].sn);

            ptr = off + 138;
            strncpy((char *) temp, (char *) ptr, 8);
            temp[8] = 0;
            util_strtrm(temp);
            ntoken = util_parse(temp, token, " ", 2, 0);
            if (ntoken == 2) {
                value = (REAL32) atof(token[0]);
                if (strcasecmp(token[1], "mV") == 0) {
                    factor = 1000.0 * 65536.0;
                } else if (strcasecmp(token[1], "uV") == 0) {
                    factor = 1000000.0 * 65536.0;
                } else if (strcasecmp(token[1], "V") == 0) {
                    factor = 1.0 * 65536.0;
                } else {
                    factor = 1.0;
                    value  = -12345.0;
                }
            } else {
                factor = 1.0;
                value  = -12345.0;
            }
            dest->chan[ndx].scale = value / factor;

            ++dest->nchan;
        }
    }

    return TRUE;

}