static void
post_command_cb(struct evhttp_request *req, void *arg) {
    size_t sz;
    int buffer_sz;
    struct evbuffer *buf;
    char *buffer = NULL;
    pid_t pid;

    log_write(INFO, "http-server: POST command cb\n");

    if (EVHTTP_REQ_POST != evhttp_request_get_command(req)) {
        log_write(WARN, "http-server: Not support this method.\n");
        evhttp_send_reply(req, 500, "not support this method", NULL);
        return;
    }
    log_write(INFO, "http-server: POST Request.\n");

    buf = evhttp_request_get_input_buffer(req);
    sz = evbuffer_get_length(buf);

    buffer = malloc(sz + 1);
    if (NULL == buffer) {
        log_write(ERROR, "http-server: alloc memory error.\n");
        evhttp_send_reply(req, 500, "alloc memroy error", NULL);
        return ;
    }

    /* Init temp buffer */
    memset(buffer, 0, sz + 1);
    buffer_sz = evbuffer_remove(buf, buffer, sz);
    if (sz != buffer_sz) {
        log_write(ERROR, "http-server: post content error. sz: %ld, buffer_sz:%ld\n", sz, buffer_sz);
        evhttp_send_reply(req, 501, "post content error", NULL);
        free(buffer);
        buffer = NULL;

        return ;
    }

    /* NEED parser POST body and executed it */
    int execrc = shell_cmd(buffer);
    if (0 == execrc) {
        log_write(INFO, "http-server: reply 200 OK. %d\n", execrc);
        evhttp_send_reply(req, 200, "OK", NULL);
    } else {
        log_write(ERROR, "fork error. %d\n", execrc);
        evhttp_send_reply(req, 502, "ERR", NULL);
    }

    free(buffer);
    buffer = NULL;

    return ;
}
Exemple #2
0
void shell(void) {
    const size_t BUFFER_LEN = 50;
    int sc;
    size_t len = 0;
    char buf[BUFFER_LEN + 1];
    buf[0] = '\0';
    shell_prompt();
    while (1) {
        asm volatile("hlt");
        sc = kbd_get_keycode();
        if (sc != -1) {
            char c = (kbd_get_shift() ? kbd_ascii_map_shift : kbd_ascii_map)[sc];
            if (c == 8) {
                if (len > 0) {
                    len--;
                    buf[len] = '\0';
                    putc(8);
                }
            } else if (c == 27) {
                while (len > 0) {
                    putc(8);
                    len--;
                }
                buf[0] = '\0';
            } else if (c == '\n') {
                putc('\n');
                shell_cmd(buf);
                len = 0;
                buf[0] = '\0';
                shell_prompt();
            } else if (kbd_get_ctrl() && c == 'c') {
                printf("^C\n");
                len = 0;
                buf[0] = '\0';
                shell_prompt();
            } else if (c && len < BUFFER_LEN) {
                buf[len++] = c;
                buf[len] = '\0';
                putc(c);
            }
        }
    }
}
Exemple #3
0
/**
 *  This directive @i{is} processed, but only if the expression begins with
 *  either a back quote (@code{`}) or an open parenthesis (@code{(}).
 *  Text within the back quotes are handed off to the shell for processing
 *  and parenthesized text is handed off to Guile.  Multiple line expressions
 *  must be joined with backslashes.
 *
 *  If the @code{shell-script} or @code{scheme-expr} do not yield @code{true}
 *  valued results, autogen will be aborted.  If @code{<anything else>} or
 *  nothing at all is provided, then this directive is ignored.
 *
 *  The result is @code{false} (and fails) if the result is empty, the
 *  number zero, or a string that starts with the letters 'n' or 'f' ("no"
 *  or "false").
 */
char *
doDir_assert(directive_enum_t id, char const * dir, char * scan_next)
{
    (void)id;
    dir = SPN_WHITESPACE_CHARS(dir);
    switch (*dir) {
    case '`':
    {
        char * pzS = (char *)dir+1;
        char * pzR = SPN_WHITESPACE_BACK(pzS, NULL);

        if (*(--pzR) != '`')
            break; /* not a valid script */

        *pzR = NUL;
        pzS = shell_cmd((char const *)pzS);
        check_assert_str(pzS, dir);
        AGFREE(pzS);
        break;
    }

    case '(':
    {
        SCM res = ag_scm_c_eval_string_from_file_line(
            dir, cctx->scx_fname, cctx->scx_line);

        check_assert_str(scm2display(res), dir);
        break;
    }

    default:
        break;
    }

    return scan_next;
}
Exemple #4
0
/**
 *  Invokes @code{$SHELL} or @file{/bin/sh} on a script that should
 *  generate AutoGen definitions.  It does this using the same server
 *  process that handles the back-quoted @code{`} text.
 *  The block of text handed to the shell is terminated with
 *  the #endshell directive.
 *
 *  @strong{CAUTION}@:  let not your @code{$SHELL} be @code{csh}.
 */
char *
doDir_shell(directive_enum_t id, char const * arg, char * scan_next)
{
    static size_t const endshell_len = sizeof("\n#endshell") - 1;

    scan_ctx_t * pCtx;
    char *       pzText = scan_next;

    (void)arg;
    (void)id;

    /*
     *  The output time will always be the current time.
     *  The dynamic content is always current :)
     */
    maxfile_time = outfile_time = time(NULL);

    /*
     *  IF there are no data after the '#shell' directive,
     *  THEN we won't write any data
     *  ELSE we have to find the end of the data.
     */
    if (strncmp(pzText, DIRECT_SHELL_END_SHELL+1, endshell_len-1) == 0)
        return scan_next;

    {
        char * pz = strstr(scan_next, DIRECT_SHELL_END_SHELL);
        if (pz == NULL)
            AG_ABEND(aprf(DIRECT_SHELL_NOEND, cctx->scx_fname,
                          cctx->scx_line));

        while (scan_next < pz) {
            if (*(scan_next++) == NL) cctx->scx_line++;
        }

        *scan_next = NUL;
    }

    /*
     *  Advance the scan pointer to the next line after '#endshell'
     *  IF there is no such line,
     *  THEN the scan will resume on a zero-length string.
     */
    scan_next = strchr(scan_next + endshell_len, NL);
    if (scan_next == NULL)
        scan_next = VOIDP(zNil);

    /*
     *  Save the scan pointer into the current context
     */
    cctx->scx_scan  = scan_next;

    /*
     *  Run the shell command.  The output text becomes the
     *  "file text" that is used for more definitions.
     */
    pzText = shell_cmd(pzText);
    if (pzText == NULL)
        return scan_next;

    if (*pzText == NUL) {
        AGFREE(pzText);
        return scan_next;
    }

    /*
     *  Get the space for the output data and for context overhead.
     *  This is an extra allocation and copy, but easier than rewriting
     *  'loadData()' for this special context.
     */
    pCtx = (scan_ctx_t *)AGALOC(sizeof(scan_ctx_t) + strlen(pzText) + 4,
                             "shell output");

    /*
     *  Link the new scan data into the context stack
     */
    pCtx->scx_next = cctx;
    cctx           = pCtx;

    /*
     *  Set up the rest of the context structure
     */
    AGDUPSTR(pCtx->scx_fname, DIRECT_SHELL_COMP_DEFS, DIRECT_SHELL_COMP_DEFS);
    pCtx->scx_scan  =
    pCtx->scx_data  = (char *)(pCtx + 1);
    pCtx->scx_line  = 0;
    strcpy(pCtx->scx_scan, pzText);
    AGFREE(pzText);

    return pCtx->scx_scan;
}
static void
spawn_option(char *value, struct request_info *request)
{
    if (dry_run == 0)
	shell_cmd(value);
}
int main(int argc, char *argv[]) {
   u32t       flen;
   void     *fdata;
   str_list   *cfg;
   char     *value;
   // just exit ;)
   if (hlp_hosttype()==QSHT_EFI) return 3;
   // check "we are called" flag
   if (sto_dword(RUN_ONCE_KEY)) {
      printf("Second configuration check call is not required.\n");
      return 2;
   }
   // read cfg file, be quiet if failed
   fdata = hlp_freadfull("OS2LDR.CFG", &flen, 0);
   if (!fdata) return 1;

   cfg   = str_settext((char*)fdata, flen);
   hlp_memfree(fdata);
   // save non-zero value to flag "we are called at least once"
   sto_savedword(RUN_ONCE_KEY, 1);
   // process config keys
   value = str_findkey(cfg, "HIDEMEM", 0);
   if (value) shell_cmd("mem hide ", value);
   // limit can be already set by VMTRR or someone else, check this too
   value = str_findkey(cfg, "MEMLIMIT", 0);
   if (value) {
      u32t limit = str2ulong(value);
      if (limit) {
         u32t oldv = sto_dword(STOKEY_MEMLIM);
         if (!oldv || limit<oldv) sto_savedword(STOKEY_MEMLIM, limit);
      }
   }
   // bootos2.exe will use this key when found no LOGSIZE parameter
   value = str_findkey(cfg, "LOGSIZE", 0);
   if (value) {
      u32t logsize = str2ulong(value);
      if (logsize>=64) sto_savedword(STOKEY_LOGSIZE, logsize); else
         log_printf("aoscfg: logsize too small (%u)!\n", logsize);
   }
   // apply DBPORT & DBCARD only if NO port selected
   if (hlp_seroutinfo(0)==0) {
      value = str_findkey(cfg, "DBCARD", 0);
      if (value) shell_cmd("dbcard ", value); else {
         value = str_findkey(cfg, "DBPORT", 0);
         if (value) {
            u32t port = str2ulong(value);
            if (port) hlp_seroutset(port, 0);
         }
      }
   }
   // ramdisk creation (only if not exist one)
   value = str_findkey(cfg, "RAMDISKNAME", 0);
   if (value) setenv("VDISKNAME", value, 1);

   value = str_findkey(cfg, "RAMDISK", 0);
   if (value) {
      qs_vdisk  dsk = NEW(qs_vdisk);
      if (dsk) {
         u32t sectors;
         qserr    res = dsk->query(0, 0, &sectors, 0, 0);
         DELETE(dsk);
         if (!res) {
            log_printf("aoscfg: ramdisk already exists (%uMb)!\n", sectors>>11);
         } else {
            shell_cmd("ramdisk ", value);
         }
      } else