Example #1
0
static char *fmt_decimal( const U64 number )
{
    static  char    fmt_dec[64];
    double  num  = (double)number;
    BYTE    size;
    int     i;

    memset(fmt_dec, 0, sizeof(fmt_dec));

    if ( num > 0 )
    {
        if ( num >= (double)ONE_TRILLION )
        {
            num /= (double)ONE_TRILLION;
            size = 'T';
        }
        else if ( num >= ONE_BILLION )
        {
            num /= (double)ONE_BILLION;
            size = 'G';
        }
        else if ( num >= (double)ONE_MILLION )
        {
            num /= (double)ONE_MILLION;
            size = 'M';
        }
        else
        {
            num /= (double)ONE_THOUSAND;
            size = 'K';
        }

        MSGBUF( fmt_dec, "%7.3f", num );

        i = (int)strlen(fmt_dec);

        if ( i > 0 )
        {
            for ( i--; i > 0; i-- )
            {
                if      ( fmt_dec[i] == '0' ) fmt_dec[i] = '\0';
                else if ( fmt_dec[i] == '.' ) { fmt_dec[i] = '\0'; break; }
                else break;
            }
        }

        fmt_dec[strlen(fmt_dec)] = '\0';
        fmt_dec[strlen(fmt_dec)+1] = '\0';
        fmt_dec[strlen(fmt_dec)+2] = '\0';
        fmt_dec[strlen(fmt_dec)] = ' ';
        fmt_dec[strlen(fmt_dec)] = size;
    }
    else
    {
        MSGBUF( fmt_dec, "%3d ", 0 );
        size = ' ';
    }

    return fmt_dec;
}
Example #2
0
DLL_EXPORT int ptt_pthread_print ()
{
int   i, n, count = 0;
char  result[32]; // (result is 'int'; if 64-bits, 19 digits or more!)
char  tbuf[256];
time_t tt;

    if (pttrace == NULL || pttracen == 0) return count;
    OBTAIN_PTTLOCK;
    n = pttracen;
    pttracen = 0;
    RELEASE_PTTLOCK;

    i = pttracex;
    do
    {
        if (pttrace[i].tid)
        {
            tt = pttrace[i].tv.tv_sec; strlcpy(tbuf, ctime(&tt),sizeof(tbuf)); tbuf[19] = '\0';

            if (pttrace[i].result == PTT_MAGIC && (pttrace[i].trclass & PTT_CL_THR))
                result[0] = '\0';
            else
                if((pttrace[i].trclass & ~PTT_CL_THR))
                    MSGBUF(result, "%8.8x", pttrace[i].result);
                else
                    MSGBUF(result, "%d", pttrace[i].result);
            logmsg
            (
                "%-18s "                           // File name
                "%s.%6.6ld "                       // Time of day (HH:MM:SS.usecs)
                I32_FMTX" "                        // Thread id (low 32 bits)
                "%-12s "                           // Trace type (string; 12 chars)
                PTR_FMTx" "                        // Data value 1
                PTR_FMTx" "                        // Data value 2
                "%s\n"                             // Numeric result (or empty string)

                ,pttrace[i].loc                    // File name
                ,tbuf + 11                         // Time of day (HH:MM:SS)
                ,pttrace[i].tv.tv_usec             // Time of day (usecs)
                ,(U32)(uintptr_t)(pttrace[i].tid)  // Thread id (low 32 bits)
                ,pttrace[i].type                   // Trace type (string; 12 chars)
                ,(uintptr_t)pttrace[i].data1       // Data value 1
                ,(uintptr_t)pttrace[i].data2       // Data value 2
                ,result                            // Numeric result (or empty string)
            );
            count++;
        }
        if (++i >= n) i = 0;
    } while (i != pttracex);
    memset( pttrace, 0, PTT_TRACE_SIZE * n );
    pttracex = 0;
    pttracen = n;
    return count;
}
Example #3
0
int history_absolute_line(int x) {
  HISTORY *tmp = history_lines_end;
  int lowlimit;
  char buf[80];

  if (history_count == 0) {
    WRMSG(HHC02293, "I", "History empty");
    return -1;
  }

  lowlimit = history_count - HISTORY_MAX;

  if (x > history_count || x <= lowlimit) {
    MSGBUF(buf, "Only commands %d-%d are in history", lowlimit<0? 1 : lowlimit + 1, history_count);
    WRMSG(HHC02293, "I", buf);
    return (-1);
  }

  while (tmp->number != x)
    tmp = tmp->prev;

  copy_to_historyCmdLine(tmp->cmdline);
  history_ptr = NULL;
  return(0);
}
Example #4
0
/*-------------------------------------------------------------------*/
int bsf_het (DEVBLK *dev, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */

    /* Exit if already at BOT */
    if (dev->curfilen==1 && dev->nxtblkpos == 0)
    {
        build_senseX(TAPE_BSENSE_LOADPTERR,dev,unitstat,code);
        return -1;
    }

    rc = het_bsf (dev->hetb);
    if (rc < 0)
    {
        char msgbuf[128];
        MSGBUF( msgbuf, "Het error '%s': '%s'", het_error(rc), strerror(errno));
        WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het", "het_bsf()", (off_t)dev->hetb->cblk, msgbuf);

        build_senseX(TAPE_BSENSE_LOCATEERR,dev,unitstat,code);
        return -1;
    }

    /* Maintain position */
    dev->blockid = rc;
    dev->curfilen--;

    /* Return success */
    return 0;

} /* end function bsf_het */
Example #5
0
/*-------------------------------------------------------------------*/
int fsf_het (DEVBLK *dev, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */

    /* Forward space to start of next file */
    rc = het_fsf (dev->hetb);
    if (rc < 0)
    {
        char msgbuf[128];
        MSGBUF( msgbuf, "Het error '%s': '%s'", het_error(rc), strerror(errno));
        WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het", "het_fsf()", (off_t)dev->hetb->cblk, msgbuf);

        if(rc==HETE_EOT)
        {
            build_senseX(TAPE_BSENSE_ENDOFTAPE,dev,unitstat,code);
        }
        else
        {
            build_senseX(TAPE_BSENSE_READFAIL,dev,unitstat,code);
        }
        return -1;
    }

    /* Maintain position */
    dev->blockid = rc;
    dev->curfilen++;

    /* Return success */
    return 0;

} /* end function fsf_het */
Example #6
0
void fmt_line( unsigned char *tbl, char *name, int start, int length)
{
    int     i, j, k, l, o;
    char    hbuf[128];
    char    cbuf[64];
    char    fmtline[256];
    BYTE    c;

    l = length < 32 ? length : 32;

    for( o = start; o < (start+length); o += l )
    {
        memset( hbuf, 0, sizeof(hbuf) );
        memset( cbuf, 0, sizeof(cbuf) );

        for (i = 0, j = 0, k = 0; i < l; i++)
        {
            c = tbl[o+i];
            if ( (i & 0x3) == 0x0 ) hbuf[j++] = SPACE;
            if ( (i & 0xf) == 0x0 ) { hbuf[j++] = SPACE; cbuf[k++] = SPACE; }

            j += snprintf( hbuf+j, sizeof(hbuf)-j, "%2.2X", c );
            cbuf[k++] = ( !isprint(c) ? '.' : c );

        } /* end for(i) */
        MSGBUF( fmtline, "%s+0x%04x%-74.74s %-34.34s", name, o, hbuf, cbuf );
        WRMSG( HHC90000, "D", fmtline );
    }

}
Example #7
0
/*-------------------------------------------------------------------*/
int write_hetmark( DEVBLK *dev, BYTE *unitstat, BYTE code )
{
int             rc;                     /* Return code               */

    if ( dev->hetb->writeprotect )
    {
        build_senseX(TAPE_BSENSE_WRITEPROTECT,dev,unitstat,code);
        return -1;
    }

    /* Write the tape mark */
    rc = het_tapemark (dev->hetb);
    if (rc < 0)
    {
        /* Handle error condition */
        char msgbuf[128];
        MSGBUF( msgbuf, "Het error '%s': '%s'", het_error(rc), strerror(errno));
        WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het", "het_tapemark()", (off_t)dev->hetb->cblk, msgbuf);

        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_WRITEFAIL,dev,unitstat,code);
        return -1;
    }

    /* Return normal status */
    dev->blockid++;

    return 0;

} /* end function write_hetmark */
Example #8
0
/*-------------------------------------------------------------------*/
static void fcb_dump(DEVBLK* dev, char *buf, unsigned int buflen)
{
    int i;
    char wrk[16];
    char sep[1];
    sep[0] = '=';
    snprintf(buf, buflen, "LOADED lpi=%d index=%d lpp=%d fcb",
                          dev->devunique.cprt_dev.lpi,
                          dev->devunique.cprt_dev.index,
                          dev->devunique.cprt_dev.lpp );
    for (i = 1; i <= dev->devunique.cprt_dev.lpp; i++)
    {
        if (dev->devunique.cprt_dev.fcb[i] != 0)
        {
            MSGBUF( wrk, "%c%d:%d",sep[0], i, dev->devunique.cprt_dev.fcb[i]);
            sep[0] = ',' ;
            if (strlen(buf) + strlen(wrk) >= buflen - 4)
            {
                /* Too long, truncate it */
                strlcat(buf, ",...", buflen);
                return;
            }
            strlcat(buf, wrk, buflen);
        }
    }
    return;
}
Example #9
0
/*-------------------------------------------------------------------*/
char *http_get_port()
{
static char msgbuf[128];

    MSGBUF( msgbuf, "%hu", http_serv.httpport );

    return msgbuf;

}
Example #10
0
/*-------------------------------------------------------------------*/
int syntax( const char* pgm )
{
    char usage[8192];
    char buflfs[64];
#ifdef CCKD_COMPRESS_ZLIB
    char *bufz = "            -z     compress using zlib [default]\n";
#else
    char *bufz = "";
#endif
#ifdef CCKD_COMPRESS_BZIP2
    char *bufbz = "            -bz2   compress using bzip2\n";
#else
    char *bufbz = "";
#endif

    strncpy( buflfs,
            (sizeof(off_t) > 4) ?
                "            -lfs   create single large output file\n" : "",
            sizeof( buflfs));

    if (strcasecmp(pgm, "ckd2cckd") == 0)
        // "Usage: ckd2cckd ...
        MSGBUF( usage ,MSG( HHC02435, "I", bufz, bufbz ) );

    else if (strcasecmp(pgm, "cckd2ckd") == 0)
        // "Usage: cckd2ckd ...
        MSGBUF( usage ,MSG( HHC02436, "I", buflfs ) );

    else if (strcasecmp(pgm, "fba2cfba") == 0)
        // "Usage: fba2cfba ...
        MSGBUF( usage ,MSG( HHC02437, "I", bufz, bufbz ) );

    else if (strcasecmp(pgm, "cfba2fba") == 0)
        // "Usage: cfba2fba ...
        MSGBUF( usage ,MSG( HHC02438, "I", buflfs ) );

    else
        // "Usage: %s ...
        MSGBUF( usage ,MSG( HHC02439, "I", pgm, bufz, bufbz, buflfs ) );

    fprintf( stdout, "%s", usage );
    return -1;
} /* end function syntax */
Example #11
0
/*---------------------------------------------------------------------------*/
static int hao_ignoremsg(char *msg)
{
#if defined(OPTION_MSGCLR) || defined(OPTION_MSGHLD)
  static int debuglen = 0;
  char* nocolor = msg;
#endif
  int msglen;

#if defined( OPTION_MSGCLR )
  /* Get past color string if there is one */
  if (!(msglen = skippnlpfx( &nocolor )))       /* Skip past <pnl pfx  */
      return TRUE;                              /* Ignore if now empty */
  if (nocolor > msg)                            /* Color prefix found? */
    memmove( msg, nocolor, msglen+1 );          /* Remove color prefix */
#else /* defined( OPTION_MSGCLR ) */
  msglen = strlen(msg);
#endif /* defined( OPTION_MSGCLR ) */

#if defined(OPTION_MSGCLR) || defined(OPTION_MSGHLD)
  if (!debuglen)
  {
    char prefix[64] = {0};
    MSGBUF( prefix, MLVL_DEBUG_PRINTF_PATTERN, "foo", 999 );
    debuglen = (int)strlen( prefix );
  }

  /* Get past debug prefix if msglevel DEBUG is active */
  if (MLVL( DEBUG ) && msglen >= debuglen)
    memmove( msg, msg + debuglen, (msglen -= debuglen)+1 );
#endif

  /* Ignore our own messages (HHC0007xx, HHC0008xx and HHC0009xx
     are reserved so that hao.c can recognize its own messages) */
  if (0
      || !strncasecmp( msg, "HHC0007", 7 )
      || !strncasecmp( msg, "HHC0008", 7 )
      || !strncasecmp( msg, "HHC0009", 7 )
  )
    return TRUE;  /* (it's one of our hao messages; ignore it) */

  /* To be extra safe, ignore any messages with the string "hao" in them */
  if (0
      || !strncasecmp( msg, "HHC00013I Herc command: 'hao ",      29 )
      || !strncasecmp( msg, "HHC00013I Herc command: 'herc hao ", 34 )
      || !strncasecmp( msg, "HHC01603I hao ",                     14 )
      || !strncasecmp( msg, "HHC01603I herc hao ",                19 )
  )
    return TRUE;  /* (it's one of our hao messages; ignore it) */

  /* Same idea but for messages logged as coming from the .rc file */
  if (!strncasecmp( msg, "> hao ", 6 ))
    return TRUE;

  return FALSE;   /* (message appears to be one we should process) */
}
Example #12
0
/*-------------------------------------------------------------------*/
char *http_get_portauth()
{
static char msgbuf[128];

    if ( http_serv.httpauth == 1)
    {
        MSGBUF( msgbuf, "auth userid<%s> password<%s>",
                ( http_serv.httpuser == NULL || strlen(http_serv.httpuser) == 0 ) ?
                                "" : http_serv.httpuser,
                ( http_serv.httppass == NULL || strlen(http_serv.httppass) == 0 ) ?
                                "" : http_serv.httppass );
    }
    else
    {
        MSGBUF( msgbuf, "%s", "noauth" );
    }

    return msgbuf;

}
Example #13
0
DLL_EXPORT char *log_dsphrdcpy(void)
{
    static char  buf[MAX_PATH+2];
    static char *pzbuf = buf;

    if ( strchr(logger_filename,SPACE) == NULL )
        pzbuf = logger_filename;
    else
        MSGBUF(buf, "'%s'", logger_filename);

    return pzbuf;
}
Example #14
0
/*-------------------------------------------------------------------*/
int syntax (char *pgm)
{
    char usage[8192];
    char buflfs[64];
#ifdef CCKD_COMPRESS_ZLIB
    char *bufz = "            -z     compress using zlib [default]\n";
#else
    char *bufz = "";
#endif
#ifdef CCKD_COMPRESS_BZIP2
    char *bufbz = "            -bz2   compress using bzip2\n";
#else
    char *bufbz = "";
#endif

    strncpy( buflfs,
            (sizeof(off_t) > 4) ?
                "            -lfs   create single large output file\n" : "",
            sizeof( buflfs));
    MSGBUF( usage, MSG_C( HHC02499, "I", pgm, "DASD copy/convert" ) );
    display_version (stderr, usage+10, FALSE);

    if (strcasecmp(pgm, "ckd2cckd") == 0)
        MSGBUF( usage ,MSG( HHC02435, "I", bufz, bufbz ) );
    else if (strcasecmp(pgm, "cckd2ckd") == 0)
        MSGBUF( usage ,MSG( HHC02436, "I", buflfs ) );
    else if (strcasecmp(pgm, "fba2cfba") == 0)
        MSGBUF( usage ,MSG( HHC02437, "I", bufz, bufbz ) );
    else if (strcasecmp(pgm, "cfba2fba") == 0)
        MSGBUF( usage ,MSG( HHC02438, "I", buflfs ) );
    else
        MSGBUF( usage ,MSG( HHC02439, "I", pgm, bufz, bufbz, buflfs ) );
    printf ("%s", usage);
    return -1;
} /* end function syntax */
Example #15
0
/*-------------------------------------------------------------------*/
static char *fmt_memsize_rounded( const U64 memsize )
{
    /* Mainframe memory and DASD amounts are reported in 2**(10*n)
     * values, (x_iB international format, and shown as x_ or x_B, when
     * x >= 1024; x when x < 1024). Open Systems and Windows report
     * memory in the same format, but report DASD storage in 10**(3*n)
     * values. (Thank you, various marketing groups and international
     * standards committees...)
     *
     * For Hercules, mainframe oriented reporting characteristics will
     * be formatted and shown as x_, when x >= 1024, and as x when x <
     * 1024. Reporting of Open Systems and Windows specifics should
     * follow the international format, shown as x_iB, when x >= 1024,
     * and x or xB when x < 1024. Reporting is done at the highest
     * integral boundary.
     *
     * Format storage in 2**(10*n) values at the highest rounded
     * (truncated) integral integer boundary.
     */

    const  char     suffix[9] = {0x00, 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'};
    static char     fmt_mem[128];   /* Max of 21 bytes used for U64 */
    register U64    mem = memsize;
    register u_int  i = 0;

    if (mem)
    {
#if SIZEOF_SIZE_T > 8
             if ( mem > ONE_YOBIBYTE )
            mem &= 0xFFFFFFFFC0000000ULL;
        else if ( mem > ONE_ZEBIBYTE )
            mem &= 0xF000000000000000ULL;
        else
#endif
             if ( mem > ONE_EXBIBYTE )
            mem &= 0xFFFC000000000000ULL;
        else if ( mem > ONE_PEBIBYTE )
            mem &= 0xFFFFFF0000000000ULL;
        else if ( mem > ONE_TEBIBYTE )
            mem &= 0xFFFFFFFFC0000000ULL;
        else if ( mem > ONE_GIBIBYTE )
            mem &= 0xFFFFFFFFFFF00000ULL;
        else if ( mem > ONE_MEBIBYTE )
            mem &= 0xFFFFFFFFFFFFFC00ULL;

        for (; i < sizeof(suffix) && !(mem & 0x03FF); mem >>= 10, ++i);
    }

    MSGBUF( fmt_mem, "%5"I64_FMT"u%c", mem, suffix[i]);

    return fmt_mem;
}
Example #16
0
/*-------------------------------------------------------------------*/
DLL_EXPORT char* get_hostinfo_str ( HOST_INFO*  pHostInfo,
                                    char*       pszHostInfoStrBuff,
                                    size_t      nHostInfoStrBuffSiz )
{
    if ( pszHostInfoStrBuff && nHostInfoStrBuffSiz )
    {
        char num_procs[64];
        if ( !pHostInfo ) pHostInfo = &hostinfo;
        
        if ( pHostInfo->num_packages     != 0 &&
             pHostInfo->num_physical_cpu != 0 &&
             pHostInfo->num_logical_cpu  != 0 )
        {
            MSGBUF( num_procs, " LP=%d, Cores=%d, CPUs=%d", pHostInfo->num_logical_cpu, 
                                pHostInfo->num_physical_cpu, pHostInfo->num_packages );
        }
        else
        {
            if ( pHostInfo->num_procs > 1 )
                MSGBUF( num_procs, " MP=%d", pHostInfo->num_procs );
            else if ( pHostInfo->num_procs == 1 )
                strlcpy( num_procs, " UP", sizeof(num_procs) );
            else
                strlcpy( num_procs,   "",  sizeof(num_procs) );
        }

        snprintf( pszHostInfoStrBuff, nHostInfoStrBuffSiz,
            _("Running on %s %s-%s. %s, %s%s"),
            pHostInfo->nodename,
            pHostInfo->sysname,
            pHostInfo->release,
            pHostInfo->version,
            pHostInfo->machine,
            num_procs
        );
        *(pszHostInfoStrBuff + nHostInfoStrBuffSiz - 1) = 0;
    }
    return pszHostInfoStrBuff;
}
Example #17
0
//
// TUNTAP_GetMTU
//
int             TUNTAP_GetMTU( char*   pszNetDevName,
                               char**  ppszMTU )
{
    struct hifr         hifr;
    int                 rc;
    char                szMTU[8] = {0};

    if( !pszNetDevName || !*pszNetDevName )
    {
        // "Invalid net device name %s"
        WRMSG( HHC00140, "E", pszNetDevName ? pszNetDevName : "NULL" );
        return -1;
    }

    if( !ppszMTU )
    {
        // HHC00136 "Error in function %s: %s"
        WRMSG(HHC00136, "E", "TUNTAP_GetMTU", "Invalid parameters" );
        return -1;
    }

    *ppszMTU = NULL;

    memset( &hifr, 0, sizeof( struct hifr ) );
    strlcpy( hifr.hifr_name, pszNetDevName, sizeof(hifr.hifr_name));

#if defined( OPTION_W32_CTCI )
    rc = TUNTAP_IOCtl( 0, SIOCGIFMTU, (char*)&hifr );
#else // (non-Win32 platforms)
    {
        int sockfd = socket( AF_INET, SOCK_DGRAM, 0 );
        rc = ioctl( sockfd, SIOCGIFMTU, &hifr );
        close( sockfd );
    }
#endif
    if( rc < 0 )
    {
        // HHC00136 "Error in function %s: %s"
        WRMSG( HHC00136, "E", "TUNTAP_GetMTU", strerror( errno ));
        return -1;
    }

    MSGBUF( szMTU, "%u", hifr.hifr_mtu );
    if (!(*ppszMTU = strdup( szMTU )))
    {
        errno = ENOMEM;
        return -1;
    }

    return 0;
}   // End of function  TUNTAP_GetMTU()
Example #18
0
int history_relative_line(int x) {
  HISTORY *tmp = history_lines_end;
  char buf[80];

  if (-x > HISTORY_MAX) {
    MSGBUF(buf, "History limited to last %d commands", HISTORY_MAX);
    WRMSG(HHC02293, "I", buf);
    return (-1);
  }

  if (-x > history_count) {
    MSGBUF(buf, "Only %d commands in history", history_count);
    WRMSG(HHC02293, "I", buf);
    return (-1);
  }

  while (x<-1) {
    tmp = tmp->prev;
    x++;
  }
  copy_to_historyCmdLine(tmp->cmdline);
  history_ptr = NULL;
  return(0);
}
Example #19
0
static void*  CTCT_ListenThread( void* argp )
{
    int          connfd;
    socklen_t    servlen;
    char         str[80];
    CTCG_PARMBLK parm;

    // set up the parameters passed via create_thread
    parm = *((CTCG_PARMBLK*) argp);
    free( argp );

    for( ; ; )
    {
        servlen = sizeof(parm.addr);

        // await a connection
        connfd = accept( parm.listenfd,
                         (struct sockaddr *)&parm.addr,
                         &servlen );

        MSGBUF( str, "%s:%d",
                 inet_ntoa( parm.addr.sin_addr ),
                 ntohs( parm.addr.sin_port ) );

        if( strcmp( str, parm.dev->filename ) != 0 )
        {
            WRMSG(HHC00974, "E", SSID_TO_LCSS(parm.dev->ssid), parm.dev->devnum,
                    parm.dev->filename, str);
            close_socket( connfd );
        }
        else
        {
            parm.dev->fd = connfd;
        }

        // Ok, so having done that we're going to loop back to the
        // accept().  This was meant to handle the connection failing
        // at the other end; this end will be ready to accept another
        // connection.  Although this will happen, I'm sure you can
        // see the possibility for bad things to occur (eg if another
        // Hercules tries to connect).  This will also be fixed RSN.
    }

    // UNREACHABLE
}
Example #20
0
/*-------------------------------------------------------------------*/
int HercCmdLine (char* pszCmdLine)
{
    int      argc;
    char*    argv[ MAX_ARGS ];
    char*    cmdline  = NULL;
    int      rc       = -1;

    /* Save unmodified copy of the command line in case
       its format is unusual and needs customized parsing. */
    cmdline = strdup( pszCmdLine );

    /* Parse the command line into its individual arguments.
       Note: original command line now sprinkled with nulls */
    parse_args( pszCmdLine, MAX_ARGS, argv, &argc );

    /* Our primary Hercules command function gets first crack. */
    if ((rc = CallHercCmd( CMDFUNC_ARGS )) != HERRINVCMD)
        goto HercCmdExit;
    ASSERT( argv[0] ); /* (herc handles any/all empty commands) */

#if defined( _FEATURE_SYSTEM_CONSOLE )
    /* See if maybe it's a command that the guest understands. */
    if ( sysblk.scpimply && can_send_command() )
        scp_command( cmdline, FALSE, sysblk.scpecho ? TRUE : FALSE );
    else
#endif
        /* Error: unknown/unsupported command */
        WRMSG( HHC01600, "E", argv[0] );

HercCmdExit:

    /* Free our saved copy */
    free( cmdline );

    if (MLVL( DEBUG ))
    {
        char msgbuf[32];
        MSGBUF( msgbuf, "RC = %d", rc );
        WRMSG( HHC90000, "D", msgbuf );
    }

    return rc;
}
Example #21
0
/*-------------------------------------------------------------------*/
char *http_get_root()
{
        char *p;
static  char msgbuf[FILENAME_MAX+3];

    if ( http_serv.httproot == NULL )
        p = "is <not specified>";

    else if ( strchr(http_serv.httproot, SPACE) != NULL )
    {
        MSGBUF( msgbuf, "'%s'", http_serv.httproot );
        p = msgbuf;
    }
    else
    {
        p = http_serv.httproot;
    }

    return p;
}
Example #22
0
/*-------------------------------------------------------------------*/
int rewind_het(DEVBLK *dev,BYTE *unitstat,BYTE code)
{
int rc;
    rc = het_rewind (dev->hetb);
    if (rc < 0)
    {
        /* Handle seek error condition */
        char msgbuf[128];
        MSGBUF( msgbuf, "Het error '%s': '%s'", het_error(rc), strerror(errno));
        WRMSG (HHC00205, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het", "het_rewind()", msgbuf);

        build_senseX(TAPE_BSENSE_REWINDFAILED,dev,unitstat,code);
        return -1;
    }
    dev->nxtblkpos=0;
    dev->prvblkpos=-1;
    dev->curfilen=1;
    dev->blockid=0;
    dev->fenced = 0;
    return 0;
}
Example #23
0
//
// Format a binary hardware MAC address into a string value.
//
// Input:
//      mac          Pointer to BYTE array containing the MAC Address
//                   that MUST be at least IFHWADDRLEN bytes long.
//
// Output:
//      ppszMACAddr  Address of a char pointer that will be updated
//                   with the malloc'ed string address of the formatted
//                   MAC Address in the format "xx:xx:xx:xx:xx:xx".
//                   It is the caller's responsibility to free() it.
//
// Returns:
//      0 on success, -1 otherwise
//
int FormatMAC( char** ppszMACAddr, BYTE* mac )
{
    char szMAC[3 * IFHWADDRLEN] = {0};

    if (!ppszMACAddr || !mac)
    {
        errno = EINVAL;
        return -1;
    }

    MSGBUF( szMAC, "%02X:%02X:%02X:%02X:%02X:%02X",
        mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );

    if (!(*ppszMACAddr = strdup( szMAC )))
    {
        errno = ENOMEM;
        return -1;
    }

    return 0;
}
Example #24
0
/*-------------------------------------------------------------------*/
int bsb_het (DEVBLK *dev, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */

    /* Back space one block */
    rc = het_bsb (dev->hetb);
    if (rc < 0)
    {
        /* Increment file number and return zero if tapemark was read */
        if (rc == HETE_TAPEMARK)
        {
            dev->blockid--;
            dev->curfilen--;
            return 0;
        }

        /* Unit check if already at start of tape */
        if (rc == HETE_BOT)
        {
            build_senseX(TAPE_BSENSE_LOADPTERR,dev,unitstat,code);
            return -1;
        }
        {
            char msgbuf[128];
            MSGBUF( msgbuf, "Het error '%s': '%s'", het_error(rc), strerror(errno));
            WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename,
                   "het", "het_bsb()", (off_t)dev->hetb->cblk, msgbuf);
        }
        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_READFAIL,dev,unitstat,code);
        return -1;
    }

    dev->blockid--;

    /* Return +1 to indicate back space successful */
    return +1;

} /* end function bsb_het */
Example #25
0
/*-------------------------------------------------------------------*/
int read_het (DEVBLK *dev, BYTE *buf, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */

    rc = het_read (dev->hetb, buf);
    if (rc < 0)
    {
        /* Increment file number and return zero if tapemark was read */
        if (rc == HETE_TAPEMARK)
        {
            dev->curfilen++;
            dev->blockid++;
            return 0;
        }

        /* Handle end of file (uninitialized tape) condition */
        if (rc == HETE_EOT)
        {
            WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het", "het_read()", (off_t)dev->hetb->cblk, "end of file (uninitialized tape)");

            /* Set unit exception with tape indicate (end of tape) */
            build_senseX(TAPE_BSENSE_ENDOFTAPE,dev,unitstat,code);
            return -1;
        }
        {
            char msgbuf[128];
            MSGBUF( msgbuf, "Het error '%s': '%s'", het_error(rc), strerror(errno));
            WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "het", "het_read()", (off_t)dev->hetb->cblk, msgbuf);
        }
        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_READFAIL,dev,unitstat,code);
        return -1;
    }
    dev->blockid++;
    /* Return block length */
    return rc;

} /* end function read_het */
Example #26
0
/*-------------------------------------------------------------------*/
int ARCH_DEP(common_load_finish) (REGS *regs)
{
int rc;
    /* Zeroize the interrupt code in the PSW */
    regs->psw.intcode = 0;

    /* Load IPL PSW from PSA+X'0' */
    if ((rc = ARCH_DEP(load_psw) (regs, regs->psa->iplpsw)) )
    {
        char buf[80];
        MSGBUF(buf, "architecture mode %s, invalid ipl psw %2.2X%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X",
                get_arch_mode_string((REGS *)0),
                regs->psa->iplpsw[0], regs->psa->iplpsw[1],
                regs->psa->iplpsw[2], regs->psa->iplpsw[3],
                regs->psa->iplpsw[4], regs->psa->iplpsw[5],
                regs->psa->iplpsw[6], regs->psa->iplpsw[7]);
        WRMSG (HHC00839, "E", PTYPSTR(sysblk.pcpu), sysblk.pcpu, buf);
        HDC1(debug_cpu_state, regs);
        return rc;
    }

    /* Set the CPU into the started state */
    regs->opinterv = 0;
    regs->cpustate = CPUSTATE_STARTED;

    /* The actual IPL (load) is now completed... */
    regs->loadstate = 0;

    /* reset sys_reset flag to indicate a active machine */
    sysblk.sys_reset = FALSE;

    /* Signal the CPU to retest stopped indicator */
    WAKEUP_CPU (regs);

    HDC1(debug_cpu_state, regs);
    return 0;
} /* end function common_load_finish */
Example #27
0
/*-------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
char           *pgmname;                /* prog name in host format  */
char           *pgm;                    /* less any extension (.ext) */
char            msgbuf[512];            /* message build work area   */
int             cckd_diag_rc = 0;       /* Program return code       */
char           *fn;                     /* File name                 */

CKDDASD_DEVHDR  devhdr;                 /* [C]CKD device hdr         */
CCKDDASD_DEVHDR cdevhdr;                /* Compressed CKD device hdr */
CKDDEV         *ckd=0;                  /* CKD DASD table entry      */
FBADEV         *fba=0;                  /* FBA DASD table entry      */

int             cmd_devhdr = 0;         /* display DEVHDR            */
int             cmd_cdevhdr = 0;        /* display CDEVHDR           */
int             cmd_l1tab = 0;          /* display L1TAB             */
int             cmd_l2tab = 0;          /* display L2TAB             */
int             cmd_trkdata = 0;        /* display track data        */
int             cmd_hexdump = 0;        /* display track data (hex)  */

int             cmd_offset = 0;         /* 1 = display data at       */
int             op_offset = 0;          /* op_offset of length       */
int             op_length = 0;          /* op_length                 */

int             cmd_cchh = 0;           /* 1 = display CCHH data     */
int             op_cc = 0;              /* CC = cylinder             */
int             op_hh = 0;              /* HH = head                 */

int             cmd_tt = 0;             /* 1 = display TT data       */
int             op_tt = 0;              /* relative track #          */

int             swapend;                /* 1 = New endianess doesn't
                                             match machine endianess */
int             n, trk=0, l1ndx=0, l2ndx=0;
off_t           l2taboff=0;             /* offset to assoc. L2 table */
int             ckddasd;                /* 1=CKD dasd  0=FBA dasd    */
int             heads=0;                /* Heads per cylinder        */
off_t           trkhdroff=0;            /* offset to assoc. trk hdr  */
int             imglen=0;               /* track length              */
char            pathname[MAX_PATH];     /* file path in host format  */
char           *strtok_str = NULL;

    /* Set program name */
    if ( argc > 0 )
    {
        if ( strlen(argv[0]) == 0 )
        {
            pgmname = strdup( UTILITY_NAME );
        }
        else
        {
            char path[MAX_PATH];
#if defined( _MSVC_ )
            GetModuleFileName( NULL, path, MAX_PATH );
#else
            strncpy( path, argv[0], sizeof( path ) );
#endif
            pgmname = strdup(basename(path));
#if !defined( _MSVC_ )
            strncpy( path, argv[0], sizeof(path) );
#endif
        }
    }
    else
    {
        pgmname = strdup( UTILITY_NAME );
    }

    pgm = strtok_r( strdup(pgmname), ".", &strtok_str);
    INITIALIZE_UTILITY( pgmname );

    /* Display the program identification message */
    MSGBUF( msgbuf, MSG_C( HHC02499, "I", pgm, "CCKD diagnostic program" ) );
    display_version (stderr, msgbuf+10, FALSE);

    /* parse the arguments */
    argc--;
    argv++ ;
    while (argc > 0) {
        if(**argv != '-') break;

        switch(argv[0][1]) {
            case 'v':  if (argv[0][2] != '\0') return syntax (pgm);
                       return 0;
            case 'd':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_devhdr = 1;
                       break;
            case 'c':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_cdevhdr = 1;
                       break;
            case '1':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_l1tab = 1;
                       break;
            case '2':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_l2tab = 1;
                       break;
            case 'a':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_cchh = 1;
                       argc--; argv++;
                       op_cc = offtify(*argv);
                       argc--; argv++;
                       op_hh = offtify(*argv);
                       break;
            case 'r':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_tt = 1;
                       argc--; argv++;
                       op_tt = offtify(*argv);
                       break;
            case 'o':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_offset = 1;
                       argc--;
                       argv++;
                       op_offset = offtify(*argv);
                       argc--;
                       argv++;
                       op_length = offtify(*argv);
                       break;
            case 't':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_trkdata = 1;
                       break;
            case 'x':  if (argv[0][2] != '\0') return syntax (pgm);
                       cmd_hexdump = 1;
                       cmd_trkdata = 1;
                       break;
            case 'g':  if (argv[0][2] != '\0') return syntax (pgm);
                       debug = 1;
                       break;
            default:   return syntax (pgm);
        }
        argc--;
        argv++;
    }
    if (argc != 1) return syntax (pgm);
    fn = argv[0];

    /* open the file */
    hostpath(pathname, fn, sizeof(pathname));
    fd = HOPEN(pathname, O_RDONLY | O_BINARY);
    if (fd < 0) {
        fprintf(stderr,
                _("cckddiag: error opening file %s: %s\n"),
                fn, strerror(errno));
        return -1;
    }

    /*---------------------------------------------------------------*/
    /* display DEVHDR - first 512 bytes of dasd image                */
    /*---------------------------------------------------------------*/
    readpos(fd, &devhdr, 0, sizeof(devhdr));
    if (cmd_devhdr) {
        fprintf(stderr, "\nDEVHDR - %d (decimal) bytes:\n",
                (int)sizeof(devhdr));
        data_dump(&devhdr, sizeof(devhdr));
    }

    /*---------------------------------------------------------------*/
    /* Determine CKD or FBA device type                              */
    /*---------------------------------------------------------------*/
    if (memcmp(devhdr.devid, "CKD_C370", 8) == 0
       || memcmp(devhdr.devid, "CKD_S370", 8) == 0) {
        ckddasd = 1;
        ckd = dasd_lookup(DASD_CKDDEV, NULL, devhdr.devtype, 0);
        if (ckd == NULL) {
            fprintf(stderr,
                    "DASD table entry not found for devtype 0x%2.2X\n",
                    devhdr.devtype);
            clean();
            exit(5);
        }
    }
    else
        if (memcmp(devhdr.devid, "FBA_C370", 8) == 0
           || memcmp(devhdr.devid, "FBA_S370", 8) == 0) {
        ckddasd = 0;
        fba = dasd_lookup(DASD_FBADEV, NULL, devhdr.devtype, 0);
        if (fba == NULL) {
            fprintf(stderr,
                    "DASD table entry not found for "
                    "devtype 0x%2.2X\n",
                    DEFAULT_FBA_TYPE);
            clean();
            exit(6);
        }
    }
    else {
        fprintf(stderr, "incorrect header id\n");
        clean();
        return -1;
    }

    /*---------------------------------------------------------------*/
    /* Set up device characteristics                                 */
    /*---------------------------------------------------------------*/
    if (ckddasd) {
        heads = ((U32)(devhdr.heads[3]) << 24)
              | ((U32)(devhdr.heads[2]) << 16)
              | ((U32)(devhdr.heads[1]) << 8)
              | (U32)(devhdr.heads[0]);
        if (debug)
            fprintf(stderr,
                "\nHHC90000D DBG: %s device has %d heads/cylinder\n",
                ckd->name, heads);
    } 


    /*---------------------------------------------------------------*/
    /* display CDEVHDR - follows DEVHDR                              */
    /*---------------------------------------------------------------*/
    readpos(fd, &cdevhdr, CKDDASD_DEVHDR_SIZE, sizeof(cdevhdr));
    if (cmd_cdevhdr) {
        fprintf(stderr, "\nCDEVHDR - %d (decimal) bytes:\n",
                (int)sizeof(cdevhdr));
        data_dump(&cdevhdr, sizeof(cdevhdr));
    }

    /*---------------------------------------------------------------*/
    /* Find machine endian-ness                                      */
    /*---------------------------------------------------------------*/
    /* cckd_endian() returns 1 for big-endian machines               */
    swapend = (cckd_endian() !=
               ((cdevhdr.options & CCKD_BIGENDIAN) != 0));

    /*---------------------------------------------------------------*/
    /* display L1TAB - follows CDEVHDR                               */
    /*---------------------------------------------------------------*/
    /* swap numl1tab if needed */
    n = cdevhdr.numl1tab;
    if (swapend) cckd_swapend4((char *)&n);

    l1 = makbuf(n * CCKD_L1ENT_SIZE, "L1TAB");
    readpos(fd, l1, CCKD_L1TAB_POS, n * CCKD_L1ENT_SIZE);
    /* L1TAB itself is not adjusted for endian-ness                  */
    if (cmd_l1tab) {
        fprintf(stderr, "\nL1TAB - %d (0x%X) bytes:\n",
                (int)(n * CCKD_L1ENT_SIZE), (unsigned int)(n * CCKD_L1ENT_SIZE));
        data_dump(l1, n * CCKD_L1ENT_SIZE);
    }

    /*---------------------------------------------------------------*/
    /* display OFFSET, LENGTH data                                   */
    /*---------------------------------------------------------------*/
    if (cmd_offset) {
        bulk = makbuf(op_length, "BULK");
        readpos(fd, bulk, op_offset, op_length);
        fprintf(stderr,
            "\nIMAGE OFFSET %d (0x%8.8X) "
            "of length %d (0x%8.8X) bytes:\n",
            op_offset, op_offset, op_length, op_length);
        data_dump(bulk, op_length);
        free(bulk);
        bulk = NULL;
    }

    /*---------------------------------------------------------------*/
    /* FBA isn't supported here because I don't know much about FBA  */
    /*---------------------------------------------------------------*/
    if ( (!ckddasd) && ((cmd_cchh) || (cmd_tt)) ) {
        fprintf(stderr, "CCHH/reltrk not supported for FBA\n");
        clean();
        exit(3);
    }

    /*---------------------------------------------------------------*/
    /* Setup CCHH or relative track request                          */
    /*---------------------------------------------------------------*/
    if (ckddasd) {
        if (cmd_tt) {
            trk = op_tt;
            op_cc = trk / heads;
            op_hh = trk % heads;
        } else {
            trk = (op_cc * heads) + op_hh;
        }
        l1ndx = trk / cdevhdr.numl2tab;
        l2ndx = trk % cdevhdr.numl2tab;
        l2taboff = l1[l1ndx];
        if (swapend) cckd_swapend4((char *)&l2taboff);
    }

    /*---------------------------------------------------------------*/
    /* display CKD CCHH or relative track data                       */
    /*---------------------------------------------------------------*/
    if ((cmd_cchh) || (cmd_tt)) {
        fprintf(stderr,
                "CC %d HH %d = reltrk %d; "
                "L1 index = %d, L2 index = %d\n"
                "L1 index %d = L2TAB offset %d (0x%8.8X)\n",
                op_cc, op_hh, trk,
                l1ndx, l2ndx,
                l1ndx, (int)l2taboff, (int)l2taboff);
        l2 = makbuf(cdevhdr.numl2tab * sizeof(CCKD_L2ENT), "L2TAB");
        readpos(fd, l2, l2taboff,
                cdevhdr.numl2tab * sizeof(CCKD_L2ENT));
        if (cmd_l2tab) {
            fprintf(stderr,
                   "\nL2TAB - %d (decimal) bytes\n",
                   (int)(cdevhdr.numl2tab * sizeof(CCKD_L2ENT)));
            data_dump(l2, (cdevhdr.numl2tab * sizeof(CCKD_L2ENT)) );
        }
        fprintf(stderr, "\nL2 index %d = L2TAB entry %d bytes\n",
               l2ndx, (int)sizeof(CCKD_L2ENT) );
        data_dump(&l2[l2ndx], sizeof(CCKD_L2ENT) );
        trkhdroff = l2[l2ndx].pos;
        imglen = l2[l2ndx].len;
        if (swapend) {
            cckd_swapend4((char *)&trkhdroff);
            cckd_swapend4((char *)&imglen);
        }
        fprintf(stderr, "\nTRKHDR offset %d (0x%8.8X); "
                "length %d (0x%4.4X)\n",
                (int)trkhdroff, (int)trkhdroff, imglen, imglen);
        tbuf = makbuf(imglen, "TRKHDR+DATA");
        readpos(fd, tbuf, trkhdroff, imglen);
        fprintf(stderr, "\nTRKHDR track %d\n", trk);
        data_dump(tbuf, sizeof(CKDDASD_TRKHDR) );
        if (cmd_trkdata) showtrk(tbuf, imglen, trk, cmd_hexdump);
        free(l2); free(tbuf);
        l2 = NULL; tbuf = NULL;
    }

    /* Close file, exit */
    fprintf(stderr, "\n");
    clean();
    return cckd_diag_rc;
}
Example #28
0
/*-------------------------------------------------------------------*/
int decomptrk(
              BYTE *ibuf,         /* input buffer address            */
              int ibuflen,        /* input buffer length             */
              BYTE *obuf,         /* output buffer address           */
              int obuflen,        /* output buffer length            */
              int heads,          /* >=0 means CKD, else FBA         */
              int trk,            /* relative track or block number  */
              char *msg           /* addr of 80 byte msg buf or NULL */
             )
/* ibuf points at CKDDASD_TRKHDR header followed by track data       */
/* ibuflen specifies length of TRKHDR and data                       */
/* This code based on decompression logic in cdsk_valid_trk.         */
/* Returns length of decompressed data or -1 on error.               */
{
#if defined( HAVE_LIBZ ) || defined( CCKD_BZIP2 )
int             rc;                     /* Return code               */
#endif
unsigned int    bufl;                   /* Buffer length             */
#ifdef CCKD_BZIP2
unsigned int    ubufl;                  /* when size_t != unsigned int */
#endif

#if !defined( HAVE_LIBZ ) && !defined( CCKD_BZIP2 )
    UNREFERENCED(heads);
    UNREFERENCED(trk);
    UNREFERENCED(msg);
#endif

    memset(obuf, 0, obuflen);  /* clear output buffer             */

    /* Uncompress the track/block image */
    switch (ibuf[0] & CCKD_COMPRESS_MASK) {

    case CCKD_COMPRESS_NONE:
        bufl = (ibuflen < obuflen) ? ibuflen : obuflen;
        memcpy (obuf, ibuf, bufl);
        break;

#ifdef HAVE_LIBZ
    case CCKD_COMPRESS_ZLIB:
        memcpy (obuf, ibuf, CKDDASD_TRKHDR_SIZE);
        bufl = obuflen - CKDDASD_TRKHDR_SIZE;
        rc = uncompress(&obuf[CKDDASD_TRKHDR_SIZE],
                         (void *)&bufl,
                         &ibuf[CKDDASD_TRKHDR_SIZE],
                         ibuflen);
        if (rc != Z_OK) {
            if (msg)
                MSGBUF(msg, "%s %d uncompress error, rc=%d;"
                         "%2.2x%2.2x%2.2x%2.2x%2.2x",
                         heads >= 0 ? "trk" : "blk", trk, rc,
                         ibuf[0], ibuf[1], ibuf[2], ibuf[3], ibuf[4]);
            return -1;
        }
        bufl += CKDDASD_TRKHDR_SIZE;
        break;
#endif

#ifdef CCKD_BZIP2
    case CCKD_COMPRESS_BZIP2:
        memcpy(obuf, ibuf, CKDDASD_TRKHDR_SIZE);
        ubufl = obuflen - CKDDASD_TRKHDR_SIZE;
        rc = BZ2_bzBuffToBuffDecompress (
                 (char *)&obuf[CKDDASD_TRKHDR_SIZE],
                 &ubufl,
                 (char *)&ibuf[CKDDASD_TRKHDR_SIZE],
                 ibuflen, 0, 0);
        if (rc != BZ_OK) {
            if (msg)
                MSGBUF(msg, "%s %d decompress error, rc=%d;"
                         "%2.2x%2.2x%2.2x%2.2x%2.2x",
                         heads >= 0 ? "trk" : "blk", trk, rc,
                         ibuf[0], ibuf[1], ibuf[2], ibuf[3], ibuf[4]);
            return -1;
        }
        bufl=ubufl;
        bufl += CKDDASD_TRKHDR_SIZE;
        break;
#endif

    default:
        return -1;

    } /* switch (buf[0] & CCKD_COMPRESS_MASK) */
    return bufl;
}
Example #29
0
/*-------------------------------------------------------------------*/
char *http_root()
{
    obtain_lock( &http_lock_root );

    /* If the HTTP root directory is not specified,
       use a reasonable default */
    if (!http_serv.httproot)
    {
#if defined(_MSVC_)
        char process_dir[HTTP_PATH_LENGTH];
        if (get_process_directory(process_dir,HTTP_PATH_LENGTH) > 0)
        {
            strlcat(process_dir,"\\html",HTTP_PATH_LENGTH);
            http_serv.httproot = strdup(process_dir);
        }
        else
#endif /*defined(WIN32)*/
        http_serv.httproot = strdup(HTTP_ROOT);
    }

    /* Convert the specified HTTPROOT value to an absolute path
       ending with a '/' and save in http_serv.httproot. */
    {
        char absolute_httproot_path[HTTP_PATH_LENGTH];
        int  rc;
#if defined(_MSVC_)
        /* Expand any embedded %var% environ vars */
        rc = expand_environ_vars( http_serv.httproot, absolute_httproot_path,
            sizeof(absolute_httproot_path) );
        if (rc == 0)
        {
            char *p = strdup(absolute_httproot_path);;
            if ( http_serv.httproot != NULL )
                free(http_serv.httproot);

            http_serv.httproot = p;
        }
#endif /* defined(_MSVC_) */
        /* Convert to absolute path */
        if (!realpath(http_serv.httproot, absolute_httproot_path))
        {
            char msgbuf[MAX_PATH+3] = { 0 };
            char *p = msgbuf;

            if ( strchr( http_serv.httproot, SPACE ) == NULL )
                p = http_serv.httproot;
            else
                MSGBUF(msgbuf, "'%s'", http_serv.httproot);

            WRMSG(HHC01801, "E", p, strerror(errno));

            release_lock( &http_lock_root );

            return NULL;
        }
        /* Verify that the absolute path is valid */
        // mode: 0 = exist only, 2 = write, 4 = read, 6 = read/write
        // rc: 0 = success, -1 = error (errno = cause)
        // ENOENT = File name or path not found.
        if (access( absolute_httproot_path, R_OK ) != 0)
        {
            char msgbuf[MAX_PATH+3];
            char *p = absolute_httproot_path;

            if ( strchr( absolute_httproot_path, SPACE ) != NULL )
            {
                MSGBUF(msgbuf, "'%s'", absolute_httproot_path);
                p = msgbuf;
            }

            WRMSG(HHC01801, "E", p, strerror(errno));

            release_lock( &http_lock_root );

            return p;
        }
        /* Append trailing [back]slash, but only if needed */
        rc = (int)strlen(absolute_httproot_path);

        if (absolute_httproot_path[rc-1] != *HTTP_PS)
            strlcat(absolute_httproot_path,HTTP_PS,sizeof(absolute_httproot_path));

        /* Save the absolute path */
        free(http_serv.httproot);

        if (strlen(absolute_httproot_path) > MAX_PATH )
        {
            char msgbuf[MAX_PATH+3] = { 0 };
            char *p = msgbuf;

            if ( strchr( absolute_httproot_path, SPACE ) == NULL )
                p = absolute_httproot_path;
            else
                MSGBUF(msgbuf, "'%s'", absolute_httproot_path);

            WRMSG(HHC01801, "E", p, "path length too long");

            release_lock( &http_lock_root );

            return NULL;
        }
        else
        {
            char    pathname[MAX_PATH];     /* working pathname          */
            char msgbuf[MAX_PATH+3];
            char *p = msgbuf;

            memset(msgbuf,0,sizeof(msgbuf));

            hostpath(pathname, absolute_httproot_path, sizeof(pathname));
            http_serv.httproot = strdup(pathname);

            if ( strchr( http_serv.httproot, SPACE ) == NULL )
                p = http_serv.httproot;
            else
                MSGBUF(msgbuf, "'%s'", http_serv.httproot);

            WRMSG(HHC01802, "I", p);
        }
    }

    release_lock( &http_lock_root );

    return http_serv.httproot;
}
Example #30
0
/*-------------------------------------------------------------------*/
int http_command(int argc, char *argv[])
{
    int rc = 0;

    if ( !http_struct_init )
    {
        memset(&http_serv,0,sizeof(HTTP_SERV));
        initialize_condition( &http_serv.http_wait_shutdown );
        initialize_lock( &http_serv.http_lock_shutdown );
        initialize_lock( &http_lock_root );
        http_struct_init = TRUE;
    }

    http_serv.httpstmtold = FALSE;

    if ( argc == 2 && CMD(argv[0],rootx,4) &&
         ( ( strlen(argv[0]) == 5 && argv[2] != NULL && strcmp(argv[2],"httproot") == 0 ) ||
           ( strlen(argv[0]) == 4 ) ) )
    {
        if ( strlen(argv[0]) == 5 )
        {
            http_serv.httpstmtold = TRUE;
        }

        obtain_lock( &http_lock_root );
        if (http_serv.httproot)
        {
            free(http_serv.httproot);
            http_serv.httproot = NULL;
        }

        if ( strlen(argv[1]) > 0 )
        {
            char    pathname[MAX_PATH];

            hostpath(pathname, argv[1], sizeof(pathname));

            if ( pathname[strlen(pathname)-1] != PATHSEPC )
                strlcat( pathname, PATHSEPS, sizeof(pathname) );

            http_serv.httproot = strdup(pathname);
        }
        release_lock( &http_lock_root );

        http_root();

        if ( MLVL(VERBOSE) )
            WRMSG(HHC02204, "I", http_serv.httpstmtold ? "httproot": "root",
                        http_serv.httproot ? http_serv.httproot : "<not specified>");

        if ( http_serv.httpstmtold )
            http_startup(TRUE);

        rc = 0;
    }
    else if ( (argc == 2 || argc == 3 || argc == 5) && CMD(argv[0],portx,4) &&
              ( ( strlen(argv[0]) == 5 && argv[5] != NULL && strcmp(argv[5],"httpport") == 0 ) ||
                ( strlen(argv[0]) == 4 ) ) )
    {
        if ( strlen(argv[0]) == 5 )
        {
            http_serv.httpstmtold = TRUE;
        }

        if ( sysblk.httptid != 0 )
        {
            WRMSG( HHC01812, "E" );
            rc = -1;
        }
        else
        {
            char c;

            if (sscanf(argv[1], "%hu%c", &http_serv.httpport, &c) != 1
                    || http_serv.httpport == 0
                    || (http_serv.httpport < 1024 && http_serv.httpport != 80) )
            {
                rc = -1;
            }
            if ( rc >= 0 && argc == 3 && CMD(argv[2],noauth,6) )
            {
                http_serv.httpauth = 0;
            }
            else if ( rc >=0 && argc == 5 && CMD(argv[2],auth,4) )
            {
                if ( strlen( argv[3] ) < 1 || strlen( argv[4] ) < 1 )
                {
                    WRMSG( HHC01814, "E" );
                    rc = -1;
                }
                else
                {
                    if (http_serv.httpuser)
                        free(http_serv.httpuser);
                    http_serv.httpuser = strdup(argv[3]);

                    if (http_serv.httppass)
                        free(http_serv.httppass);
                    http_serv.httppass = strdup(argv[4]);

                    http_serv.httpauth = 1;
                }
            }
            else if ( argc != 2 || rc < 0 )
            {
                WRMSG( HHC02299, "E", "http" );
                rc = -1;
            }

            if ( rc >= 0 && MLVL(VERBOSE) )
            {
                char msgbuf[128];
                if ( http_serv.httpauth == 1 )
                {
                    MSGBUF( msgbuf, "port=%hu auth userid<%s> password<%s>",
                            http_serv.httpport,
                          ( http_serv.httpuser == NULL || strlen(http_serv.httpuser) == 0 ) ?
                                "" : http_serv.httpuser,
                          ( http_serv.httppass == NULL || strlen(http_serv.httppass) == 0 ) ?
                                "" : http_serv.httppass );
                }
                else
                    MSGBUF( msgbuf, "port=%hu noauth", http_serv.httpport );

                WRMSG( HHC02204, "I", http_serv.httpstmtold ? "httpport":"port", msgbuf );

                if ( http_serv.httpstmtold )
                    http_startup(TRUE);

            }   /* VERBOSE */
        }
    }
    else if ( argc == 1 && CMD(argv[0],start,3) )
    {
        if ( http_serv.httpport == 0 )
        {
            WRMSG( HHC01815, "E", "not valid");
            rc = -1;
        }
        else
            rc = http_startup(FALSE);
    }
    else if (argc == 1 && CMD(argv[0],stop,4))
    {
        if ( sysblk.httptid != 0 )
        {
            http_shutdown(NULL);
            WRMSG( HHC01805, "I" );
            rc = 1;
        }
        else
        {
            http_serv.httpshutdown = TRUE;
            WRMSG( HHC01806, "W", "already stopped" );
            rc = 1;
        }
    }
    else if ( argc == 0 )
    {
        if ( sysblk.httptid != 0 )
        {
            if ( http_serv.httpbinddone )
            {
                WRMSG( HHC01809, "I" );
                rc = 0;
            }
            else
            {
                WRMSG( HHC01813, "I" );
                rc = 1;
            }
        }
        else
        {
            WRMSG( HHC01810, "I" );
            rc = 1;
        }

        WRMSG(HHC01811, "I", http_get_root());

        WRMSG(HHC01808, "I", http_get_port(), http_get_portauth());
    }
    else
    {
        WRMSG( HHC02299, "E", "http" );
        rc = -1;
    }
    return rc;
}