Beispiel #1
0
void
prepare_xml_file (char *filename)
{
    int
    rc;

    rc = xml_load_file (& xml_root, PATH, filename, FALSE);
    if (rc == XML_NOERROR)
    {
        xml_source = xml_first_child (xml_root);
        if (xml_source)
        {
            xml_put_attr (xml_switches, "filename", filename);
            xml_put_attr (xml_switches, "template", "1");
        }
        else
            xml_free (xml_root);
    }
    else
    {
        coprintf ("%s E: Error processing %s...", me, filename);
        coprintf (xml_error ());
        raise_exception (anomaly_event);
    }
}
Beispiel #2
0
MODULE display_command_line_syntax (void)
{
    coprintf ("syntax: %s -<option> ... -<attr>[:<value>] ... <filename> ...", me);
    coprintf ("    Options:");
    coprintf ("        -q   quiet: suppress routine messages");
    coprintf ("        -h   help:     show command-line summary");
    coprintf ("        -v   version: show full version information");
}
Beispiel #3
0
static void
execute_smt (void)
{
    Bool
        cont = TRUE;
    EVENT
       *event;
    struct_ggscrp_error
       *ggscrp_error;
    struct_ggscrp_done
       *ggscrp_done;
    char
       *ptr;

    while (cont)
      {
        while (cont && (myqueue-> cur_events == 0))
            cont = smt_exec_step ();

        if (myqueue-> cur_events)
          {
            event = event_accept (myqueue, NULL);
            coprintf ("Received event: %s", event-> name);
            if (streq (event-> name, GGSCRP_ERROR))
              {
                get_ggscrp_error (event-> body, & ggscrp_error);

                coprintf ("From job: %i", 
                          ggscrp_error-> job);
                ptr = strtok (ggscrp_error-> error_text, "\n");
                while (ptr)
                  {
                    coprintf ("(%s %u): %s", ggscrp_error-> error_name,
                                             ggscrp_error-> error_line,
                                             ptr);

                    ptr = strtok (NULL, "\n");
                  }
                free_ggscrp_error (& ggscrp_error);
              }
            else
            if (streq (event-> name, GGSCRP_DONE))
              {
                get_ggscrp_done (event-> body, & ggscrp_done);

                coprintf ("From job: %i  Size=%u", 
                          ggscrp_done-> job,
                          ((SCRIPT_SOURCE *) ggscrp_done-> script_source) -> size);
                close_script ((SCRIPT_SOURCE *) ggscrp_done-> script_source);
                free_ggscrp_done (& ggscrp_done);
              }

            event_destroy (event);
          }
      }
}
Beispiel #4
0
int main (int argc, char *argv [])
{
    bin_name = strip_file_path (argv[0]);

    if (argc < 2 || argc > 3)
      {
         display_usage ();
         return -1;
      }

    if (! load_config (argv[1]) )
        return -1;

    if (argc == 3)
      {
        if (!load_body (argv[2]))
          {
            coprintf ("bad body file");
            return -1;
          }
      }

    coprintf (
        "Sending one mail from [%s] to [%s] via [%s]",
        main_sender,
        main_dest,
        main_server
      );

    smt_init ();                   /*  Initialise SMT kernel    */
    /*  Application is latent - initialise it                   */
    if (agent_lookup (SMT_SOCKET) == NULL)
        sock_init ();
    if (agent_lookup (AGENT_NAME) == NULL)
        tstsmtp_init ();

    thread_create (AGENT_NAME, "");

    /*  Application is active - execute it                      */
    smt_exec_full ();              /*  Run until completed      */

    /*  Application is halted - terminate it                    */
    smt_term ();                   /*  Shut-down SMT kernel     */
    sock_term ();

    mem_free (main_server);
    mem_free (main_sender);
    mem_free (main_dest);
    mem_free (main_body);

    printf ("Allocs=%ld frees=%ld\n", mem_allocs (), mem_frees ());
    mem_assert ();

    return (0);
}
Beispiel #5
0
MODULE read_xml_or_gsl_file (void)
{
    char
    *ch,
    *fname;
    int
    rc;

    if (!switch_quiet)
        coprintf ("%s I: Processing %s...", me, filename);

    ch = strrchr (filename, '.');
    if (ch)
    {
        if (streq (ch + 1, "gsl"))
        {
            prepare_gsl_file (filename);
            return;
        }
        else if (streq (ch + 1, "xml"))
        {
            prepare_xml_file (filename);
            return;
        }
    }

    rc = xml_seems_to_be (PATH, filename);
    if (rc == XML_NOERROR)
    {
        prepare_xml_file (filename);
        return;
    }
    if (rc == XML_LOADERROR)
    {
        prepare_gsl_file (filename);
        return;
    }

    fname = file_where ('r', PATH, filename, "gsl");
    if (fname)
    {
        prepare_gsl_file (filename);
        return;
    }
    else
    {
        coprintf ("%s E: Error processing %s...", me, filename);
        coprintf ("File not found");
        raise_exception (anomaly_event);
    }
}
Beispiel #6
0
MODULE connect_to_server (THREAD *thread)
{
    tcb = thread-> tcb;                 /*  Point to thread's context        */

    if (dns_debug_mode)
      {
        inaddr.s_addr = tcb-> cur_request-> ns_ip;
        coprintf ("Connect to : %s (%s) port %d",
                  inet_ntoa (inaddr),
                  tcb-> cur_request-> ns_name?
                      tcb-> cur_request-> ns_name: "",
                  ntohs (tcb-> cur_request-> ns_port));
      }
    tcb-> current_ns_ip = tcb-> cur_request-> ns_ip;

    send_smtsock_connect (
        &sockq,
        30,                             /*  Time out for connect             */
        "udp",
        NULL,
        NULL,
        ntohs (tcb-> cur_request-> ns_port),
        ntohl (tcb-> cur_request-> ns_ip),
        0);
}
Beispiel #7
0
MYSQLHANDLE *
alloc_mysql_handle    (char *table_name, void *context)
{
    MYSQLHANDLE
        *handle = NULL;                 /* mysql Context handle                */
    MYSQL_CONNECT_CTX
        *temp_ctx,
        *ctx;
    if (context)
      {
        ctx = (MYSQL_CONNECT_CTX *)context;
        temp_ctx = dbio_mysql_connect (ctx-> dbname, ctx-> user, ctx->password,
                                       ctx->host);
        if (temp_ctx)
          {
            handle = mem_alloc (sizeof (MYSQLHANDLE));
            if (handle)
              {
                memset (handle, 0, sizeof (MYSQLHANDLE));
                handle-> db_handle = temp_ctx-> db_handle;
                if (table_name && strused (table_name))
                    handle-> table_name = mem_strdup (table_name);
                mem_free (temp_ctx);
              }
            else
              {
                coprintf ("DBIO MYSQL: Error in alloc_mysql_handle (Memory Allocation)");
                dbio_mysql_disconnect (temp_ctx);
              }
          }
      }
    return (handle);
}
Beispiel #8
0
MODULE connect_to_server (THREAD *thread)
{
    tcb = thread-> tcb;                 /*  Point to thread's context        */

    if (dns_debug_mode)
      {
        inaddr.s_addr = tcb-> cur_request-> ns_ip;
        coprintf ("Connect to : %s (%s) port %d",
                  inet_ntoa (inaddr),
                  tcb-> cur_request-> ns_name?
                      tcb-> cur_request-> ns_name: "",
                  ntohs (tcb-> cur_request-> ns_port));
      }
    tcb-> current_ns_ip = tcb-> cur_request-> ns_ip;
    msg_size = exdr_writed (&msg, SMT_SOCK_CONNECT,
        30,                             /*  Time out of connect              */
        "udp",
        NULL,
        NULL,
        ntohs (tcb-> cur_request-> ns_port),
        ntohl (tcb-> cur_request-> ns_ip),
        0);

    event_send (
        &sockq,                        /*  Send to specified queue           */
        &thread-> queue-> qid,         /*  Queue for reply                   */
        "CONNECT",                     /*  Name of event to send             */
        msg_body, msg_size,            /*  Event body and size               */
        NULL, NULL, NULL,              /*  No response events                */
        0);                            /*  No timeout                        */
}
Beispiel #9
0
Bool load_config (const char *filename)
{
    int rc;
    XML_ITEM *config = NULL;
    XML_ITEM *root   = NULL;
    char fullname[FILE_NAME_MAX + 1];

    root = xml_create ("root", NULL);

    ASSERT (filename != NULL);
    ASSERT (strlen(filename) < FILE_NAME_MAX);
    default_extension (fullname, filename, "cfg");

    rc = xml_load_file (&root, ".", fullname, FALSE);

    if (rc != XML_NOERROR)
      {
        coprintf ("Error while loading \"%s\". Check file presence and consistence",
                   fullname);
        display_usage ();
        return FALSE;;
      }

    config = xml_first_child (root);
    ASSERT (config);

    /* default server is localhost */
    main_server =   mem_strdup (xml_get_attr (config, "smtp",    "127.0.0.1"));
    main_sender =   mem_strdup (xml_get_attr (config, "sender",  "admin@crjo"));
    main_dest   =   mem_strdup (xml_get_attr (config, "dest",    "user@crjo"));

    xml_free (root);

    return TRUE;
}
Beispiel #10
0
Bool load_body (const char *filename)
{
    FILE *file = NULL;
    char *fullname = NULL;
    size_t bytes_read, size;

    ASSERT (filename);

    fullname = mem_strdup (file_where ('s', NULL, filename, "txt"));
    ASSERT (fullname);


    file = file_locate (NULL, filename, "txt");
    if (!file)
      {
        coprintf ("ERROR : unable to open file %s", fullname);
        mem_free (fullname);
        return FALSE;
      }


    size = get_file_size (fullname);

    main_body = mem_alloc (size+1);
    ASSERT (main_body);

    bytes_read = fread (main_body, 1, size, file);
    ASSERT (bytes_read == size);

    main_body[size] = 0;

    mem_free (fullname);
    return TRUE;
}
Beispiel #11
0
local
read_from_wtp_socket (size_t readsize, byte *buffer)
{
    size_t
        bytes_read;
    int
        rc;

    ASSERT (wtp_socket != 0);
    bytes_read = 0;

    while (bytes_read < readsize)
      {
        rc = read_TCP (wtp_socket, buffer + bytes_read,
                                 readsize - bytes_read);

        /*  If socket from parent is closed, the application has been
         *  shut-down, so we can stop too.
         */
        if (rc == 0 || sockerrno == EPIPE || sockerrno == ECONNRESET)
          {
            wtp_close ();
            exit (EXIT_SUCCESS);         
          }
        else
        if (rc == SOCKET_ERROR)
          {
            coprintf ("Cannot read from socket: %s\n", sockmsg ());
            exit (EXIT_FAILURE);
          }
        bytes_read += rc;
      }
}
Beispiel #12
0
MODULE set_debug_mode (THREAD *thread)
{
    tcb = thread-> tcb;                 /*  Point to thread's context        */
    dns_debug_mode = TRUE;
    console_set_mode (CONSOLE_TIME);
    console_capture  (".\\nshost.log", 'a');
    coprintf ("Debug mode ON, console output logged to file 'nshost.log'");
}
Beispiel #13
0
MODULE display_ok (THREAD *thread)
{
    tcb = thread-> tcb;                 /*  Point to thread's context        */

    coprintf ("the mail was successfully sent");

    the_next_event = ok_event;
}
Beispiel #14
0
MODULE display_error (THREAD *thread)
{
    struct_smtsmtp_reply *smtp_reply;

    get_smtsmtp_reply (thread-> event-> body, &smtp_reply);
    coprintf ("SMPT ERROR (%i) : %s", smtp_reply-> code, smtp_reply-> msg);
    free_smtsmtp_reply (&smtp_reply);

    the_next_event = ok_event;
}
Beispiel #15
0
static
char *generate_body (word length)
{
    char
        *body = NULL;
    dword
        size,
        idx;
    static char
        now_str[BUF_SIZE];
    static char
        date_str[BUF_SIZE];
    int
        rc;

    randomize ();

    ASSERT (length > 100);              /* precondition */

    body = mem_alloc (length+1);

    rc = snprintf (now_str, BUF_SIZE, "%s", conv_time_pict (time_now(), "hh:mm"));
    ASSERT (rc > 0);
    rc = snprintf (date_str, BUF_SIZE, "%s", conv_date_pict (date_now(), "yymmdd"));
    ASSERT (rc > 0);

    rc = snprintf (body, length, "automatic body generated %s-%s\n",date_str, now_str);
    ASSERT (rc > 0);

    size = strlen (body);

    coprintf ("Size [%i] - Length [%i]", size, length);
    for (idx=size; idx<length; idx++)
        body[idx] = 'A' + random(26);

    coprintf ("idx : %i", idx);
    body[idx] = 0;

    return body;
}
Beispiel #16
0
void display_usage (void)
{
    const char *usage =
"\n"
"USAGE:\n"
"\n"
"    %s tst_cfg [body]\n"
"\n"
"where:\n"
"  tst_cfg is an XML file:\n"
"    <test_config (smtp, sender, dest) />\n"
"    with smtp, sender and dest as XML attributes\n"
"  body is a file with body to send. if no file, body is generated\n"
"     '.txt' extension is assumed if no extension\n";

    coprintf (usage, bin_name);
}
Beispiel #17
0
void
wtp_write (
    const byte *buffer,                 /*  Address of data to write         */
    size_t      size)                   /*  Amount of data to write          */
{
    qbyte
        netsize;                        /*  Size in network order, 4 bytes   */

    ASSERT (wtp_socket != 0);

    /*  Write buffer size in hi-lo order                                     */
    netsize = htonl (size);
    if (write_TCP (wtp_socket, &netsize, 4)  == SOCKET_ERROR
    ||  write_TCP (wtp_socket, buffer, size) == SOCKET_ERROR)
      {
        coprintf ("Cannot write to socket: %s\n", sockmsg ());
        exit (EXIT_FAILURE);
      }
}
Beispiel #18
0
void
wtp_ready (void)
{
    byte
        *buffer;
    size_t
        size;

    size = put_wtp_msg_ready (
        &buffer,
        WTP_READY);                     /*  Message type                     */

    wtp_write (buffer, size);
    mem_free  (buffer);
    if (!wtp_expect_ok ())
      {
        coprintf ("Did not receive WTP_OK when ready.\n");
        exit (EXIT_FAILURE);
      }
}
Beispiel #19
0
void
wtp_open (
    const char *version,                /*  WTP version                      */
    const char *protocol,               /*  Protocol from command-line       */
    const char *port)                   /*  Port from command-line           */
{
    ASSERT (streq (version, "WTP/1.0"));
    ASSERT (streq (protocol, "tcp"));

    sock_init ();
    ip_nonblock = FALSE;                /*  Use blocking socket i/o          */

    wtp_socket  = connect_TCP (NULL, port);
    if (wtp_socket == INVALID_SOCKET)
      {
        coprintf ("Cannot connect to port %s: %s (%s)\n",
                   port, connect_errlist [connect_error ()], sockmsg ());
        exit (EXIT_FAILURE);
      }
    socket_nodelay (wtp_socket);        /*  Disable Nagle's Algorithm        */
}
Beispiel #20
0
void *
dbio_mysql_connect (char *name, char *user, char *pwd, char *host)
{
    MYSQL_CONNECT_CTX
        *handle = NULL;
    MYSQL
        *mysql;


    mysql = mysql_connect (NULL, host, user, pwd);
    if (mysql)
      {
        if (mysql_select_db (mysql, name) != 0)
          {
            mysql_close (mysql);
            mysql = NULL;
          }
      }
    if (mysql)
      {
        handle = mem_alloc (sizeof (MYSQL_CONNECT_CTX));
        memset (handle, 0,  sizeof (MYSQL_CONNECT_CTX));
        handle-> db_handle = mysql;
        handle-> port      = MYSQL_PORT;
        strcpy (handle-> dbname, name);
        if (user && strused (user))
            strcpy (handle-> user,     user);
        if (pwd  && strused (pwd))
            strcpy (handle-> password, pwd);
        if (host && strused (host))
            strcpy (handle-> host,     host);
      }
    else
        coprintf ("Error on Connect to %s in MySql", name);
    
    return ((void *)handle);
}
Beispiel #21
0
void
wtp_register (
    const char *program,                /*  Name of program to register      */
    Bool  is_root)                      /*  Is this a root program?          */
{
    byte
        *buffer;
    size_t
        size;

    size = put_wtp_msg_register (
        &buffer,
        WTP_REGISTER,                   /*  Message type                     */
        (char *) program,               /*  Program to register              */
        (byte) is_root);                /*  Root flag, 1 or 0                */

    wtp_write (buffer, size);
    mem_free  (buffer);
    if (!wtp_expect_ok ())
      {
        coprintf ("Registration for program '%s' failed.\n", program);
        exit (EXIT_FAILURE);
      }
}
Beispiel #22
0
static void
execute_smt (void)
{
    Bool
        cont = TRUE;
    EVENT
       *event;
    struct_ggpars_eof
       *ggpars_eof;
    struct_ggpars_ok
       *ggpars_ok;
    struct_ggpars_error
       *ggpars_error;
    SCRIPT_NODE
       *script_root;
    XML_ITEM
       *xml_item;
    MEMTRN
        *memtrn;
    JOBID
        job;
    DESCR
        *xml_descr;

    while (cont)
      {
        while (cont && (myqueue-> cur_events == 0))
            cont = smt_exec_step ();

        if (myqueue-> cur_events)
          {
            event = event_accept (myqueue, NULL);
            coprintf ("Received event: %s", event-> name);

            if (streq (event-> name, GGPARS_EOF))
              {
                get_ggpars_eof (event-> body, & ggpars_eof);
                job = ggpars_eof-> job;
                coprintf ("Finished job: %i File: %s",
                          job,
                          gsl_argv [(long) job]);
                free_ggpars_eof (& ggpars_eof);
                file_close (scriptfiles [(long) job]);
                scriptfiles [(long) job] = NULL;
              }
            else if (streq (event-> name, GGPARS_OK))
              {
                get_ggpars_ok (event-> body, & ggpars_ok);
                job = ggpars_ok-> job;
                coprintf ("From job: %i File: %s Size = %lu",
                          job,
                          gsl_argv [(long) job],
                          ggpars_ok-> size);
                script_root = (SCRIPT_NODE *) ggpars_ok-> parse_root;
                memtrn =  (MEMTRN *) ggpars_ok-> parse_memtrn;
                free_ggpars_ok (& ggpars_ok);

                xml_item = gg_xml (script_root);
                xml_save_file (xml_item, "testpars.tmp");
                xml_descr = file_slurp ("testpars.tmp");
                coprintf ("%s", xml_descr-> data);
                mem_free (xml_descr);
                file_delete ("testpars.tmp");
                xml_free (xml_item);
                gg_free (script_root);
                memt_assert (memtrn);
                mem_rollback (memtrn);

                if (! gg_parse_template (read_script, job, myqueue))
                    cont = TRUE;

              }
            else if (streq (event-> name, GGPARS_ERROR))
              {
                get_ggpars_error (event-> body, & ggpars_error);
                job = ggpars_error-> job;
                coprintf ("From job: %i File: %s",
                          job,
                          gsl_argv [(long) job]);
                coprintf ("%s", ggpars_error-> error_text);

                free_ggpars_error (& ggpars_error);

                if (! gg_parse_template (read_script, job, myqueue))
                    cont = TRUE;
              }
            coprintf ("");

            event_destroy (event);
          }
      }
}
Beispiel #23
0
static void
execute_smt (void)
{
    Bool
        cont = TRUE;
    EVENT
       *event;
    struct_ggcode_call_error
       *ggcode_call_error;
    char
       *ptr;
    SCRIPT_HANDLE
        *script_handle;
    SCRIPT_LINE
        *script_line;
    static char
        buffer [LINE_MAX + 1];

    while (cont)
      {
        while (cont && (myqueue-> cur_events == 0))
            cont = smt_exec_step ();

        if (myqueue-> cur_events)
          {
            event = event_accept (myqueue, NULL);
            coprintf ("Received event: %s", event-> name);
            if (streq (event-> name, GGCODE_CALL_ERROR)
            ||  streq (event-> name, GGCODE_CALL_MESSAGE))
              {
                get_ggcode_call_error (event-> body, & ggcode_call_error);

                ptr = strtok (ggcode_call_error-> error_text, "\n");
                while (ptr)
                  {
                    coprintf ("(%s %u): %s", ggcode_call_error-> error_name,
                                             ggcode_call_error-> error_line,
                                             ptr);

                    ptr = strtok (NULL, "\n");
                  }
                free_ggcode_call_error (& ggcode_call_error);
              }
            else
            if (streq (event-> name, GGCODE_CALL_OK))
              {
                script_handle = result. value. i;
                coprintf ("<script links=\"%lu\" path=\"%s\" name=\"%s\" timestamp=\"%lu\" >",
                          script_handle-> links,
                          script_handle-> path,
                          script_handle-> name,
                          script_handle-> timestamp);
                script_line = (SCRIPT_LINE *) script_handle-> line_head. next;
                while (script_line != (SCRIPT_LINE *) & script_handle-> line_head)
                  {
                    snprintf (buffer, LINE_MAX,
                              "    <line links=\"%u\" number=\"%u\" type=\"%s\" ",
                              script_line-> links,
                              script_line-> line,
                              node_type_string (script_line-> node-> type));
                    if (script_line-> loop_start)
                        strcat (buffer, strprintf ("loop_start=\"%u\" ",
                                                   script_line-> loop_start-> line));
                    if (script_line-> block_end)
                        strcat (buffer, strprintf ("block_end=\"%u\" ",
                                                   script_line-> block_end-> line));
                    strcat (buffer, ">");                                                   
                    coprintf ("%s", buffer);
                    script_line = script_line-> next;
                  }
                coprintf ("</script>");
                script_handle_link    (script_handle);
                script_handle_destroy (script_handle);
              }

            event_destroy (event);
          }
      }
}
Beispiel #24
0
MODULE display_end_of_search (THREAD *thread)
{
    coprintf ("%s not found !!!", buffer);
    the_next_event = ok_event;
}
Beispiel #25
0
int
main (int argc, char *argv [])
{
    int
        argn;                           /*  Argument number                  */
    Bool
        args_ok = TRUE,                 /*  Were the arguments okay?         */
        quiet_mode = FALSE;             /*  -q means suppress messages       */
    char
        *port,                          /*  Port to connect to               */
        **argparm;                      /*  Argument parameter to pick-up    */
    static char
        command [LINE_MAX];             /*  Command to pass to agent         */

    /*  These are the arguments we may get on the command line               */
    port       = NULL;
    strclr (command);

    argparm = NULL;                     /*  Argument parameter to pick-up    */
    for (argn = 1; argn < argc; argn++)
      {
        /*  If argparm is set, we have to collect an argument parameter      */
        if (argparm)
          {
            if (*argv [argn] != '-')    /*  Parameter can't start with '-'   */
              {
                *argparm = strdupl (argv [argn]);
                argparm = NULL;
              }
            else
              {
                args_ok = FALSE;
                break;
              }
          }
        else
        if (*argv [argn] == '-')
          {
            switch (argv [argn][1])
              {
                /*  These switches take a parameter                          */
                case 'p':
                    argparm = &port; break;

                /*  These switches have an immediate effect                  */
                case 'q':
                    quiet_mode = TRUE;
                    break;
                case 't':
                    smtsock_trace (TRUE);
                    break;
                case 'v':
                    coprintf ("Syscli %s", SYSCLI_VERSION);
                    coprintf (PRODUCT);
                    coprintf (BUILDMODEL);
                    coprintf (COPYRIGHT);
                    coprintf ("Built on: %s", BUILDDATE);
                    exit (EXIT_SUCCESS);
                case 'h':
                    coprintf ("Syscli %s", SYSCLI_VERSION);
                    coprintf (COPYRIGHT);
                    coprintf (USAGE);
                    exit (EXIT_SUCCESS);

                /*  Anything else is an error                                */
                default:
                    args_ok = FALSE;
              }
          }
        else
          {
            strcat (command, " ");
            strcat (command, argv [argn]);
          }
      }

    /*  If there was a missing parameter or an argument error, quit          */
    if (argparm)
      {
        puts ("Argument missing - type 'syscli -h' for help");
        exit (EXIT_FAILURE);
      }
    else
    if (!args_ok)
      {
        puts ("Invalid arguments - type 'syscli -h' for help");
        exit (EXIT_FAILURE);
      }
    
    /*  Handle the remaining arguments we got                                */
    if (!port)
        port = SYSMAN_DEFAULT_PORT;
    if (quiet_mode)
      {
        fclose (stdout);                /*  Kill standard output             */
        fclose (stderr);                /*   and standard error              */
      }
    else
      {
        puts ("Syscli " SYSCLI_VERSION);
        puts (COPYRIGHT);
      }

    smt_init ();                        /*  Initialise SMT kernel            */
    sysclia_init (command, port);       /*  Initialise SYSMAN client agent   */
    smt_exec_full ();                   /*  Run until completed              */
    smt_term ();                        /*  Shut-down SMT kernel             */
    mem_assert ();                      /*  Assert memory is clean           */
    return (0);
}
Beispiel #26
0
int
main (int argc, char *argv [])
{
    int
        argn;                           /*  Argument number                  */
    Bool
        args_ok = TRUE,                 /*  Were the arguments okay?         */
        quiet_mode = FALSE,             /*  -q means suppress messages       */
        background = FALSE;             /*  -s means run in background       */
    char
        *workdir,                       /*  Working directory                */
        *port,                          /*  Value for listen port            */
        **argparm;                      /*  Argument parameter to pick-up    */

    /*  First off, switch to user's id                                       */
    set_uid_user ();

    /*  These are the arguments we may get on the command line               */
    workdir    = NULL;
    port       = NULL;

    argparm = NULL;                     /*  Argument parameter to pick-up    */
    for (argn = 1; argn < argc; argn++)
      {
        /*  If argparm is set, we have to collect an argument parameter      */
        if (argparm)
          {
            if (*argv [argn] != '-')    /*  Parameter can't start with '-'   */
              {
                *argparm = strdupl (argv [argn]);
                argparm = NULL;
              }
            else
              {
                args_ok = FALSE;
                break;
              }
          }
        else
        if (*argv [argn] == '-')
          {
            switch (argv [argn][1])
              {
                /*  These switches take a parameter                          */
                case 'w':
                    argparm = &workdir;  break;
                case 'p':
                    argparm = &port; break;

                /*  These switches have an immediate effect                  */
                case 'q':
                    quiet_mode = TRUE;
                    break;
                case 's':
                    background = TRUE;
                    break;
                case 'S':
                    background = FALSE;
                    break;
                case 't':
                    smtsock_trace (TRUE);
                    break;
                case 'v':
                    coprintf ("Sysman %s", SYSMAN_VERSION);
                    coprintf (PRODUCT);
                    coprintf (BUILDMODEL);
                    coprintf (COPYRIGHT);
                    coprintf ("Built on: %s", BUILDDATE);
                    exit (EXIT_SUCCESS);
                case 'h':
                    coprintf ("Sysman %s", SYSMAN_VERSION);
                    coprintf (COPYRIGHT);
                    coprintf (USAGE);
                    exit (EXIT_SUCCESS);

                /*  Anything else is an error                                */
                default:
                    args_ok = FALSE;
              }
          }
        else
          {
            args_ok = FALSE;
            break;
          }
      }

    /*  If there was a missing parameter or an argument error, quit          */
    if (argparm)
      {
        puts ("Argument missing - type 'sysman -h' for help");
        exit (EXIT_FAILURE);
      }
    else
    if (!args_ok)
      {
        puts ("Invalid arguments - type 'sysman -h' for help");
        exit (EXIT_FAILURE);
      }
      
    /*  Set server working directory if necessary                            */
    if (workdir
    &&  set_curdir (workdir))
      {
        printf ("Can't work in '%s' - %s\n", workdir, strerror (errno));
        exit (EXIT_FAILURE);
      }
    
    /*  Handle the remaining arguments we got                                */
    if (!port)
        port = SYSMAN_DEFAULT_PORT;
    if (quiet_mode)
      {
        fclose (stdout);                /*  Kill standard output             */
        fclose (stderr);                /*   and standard error              */
      }
    else
      {
        puts ("Sysman " SYSMAN_VERSION);
        puts (COPYRIGHT);
      }

    if (background)
      {
        const char
           *background_args [] = { "-s", NULL };

        puts ("Moving into the background");
        if (process_server (NULL, NULL, argc, argv, background_args) != 0)
          {
            puts ("Backgrounding failed.  Giving up.");
            exit (EXIT_FAILURE);
          }
      }

    smt_init ();                        /*  Initialise SMT kernel            */
    if (sysmana_init (port) == 0)       /*  Initialise SYSMAN agent          */
        smt_exec_full ();               /*  Run until completed              */
    else
        printf ("Initialisation error\n");
    smt_term ();                        /*  Shut-down SMT kernel             */

    mem_assert ();

    return (EXIT_SUCCESS);
}
Beispiel #27
0
int
coputs (const char *string)
{
    coprintf ("%s", string);
    return (1);
}
Beispiel #28
0
MODULE display_invalid_command (THREAD *thread)
{
    tcb = thread-> tcb;                 /*  Point to thread's context        */
    coprintf ("%s: ERROR, invalid command");
}
Beispiel #29
0
int
main (int argc, char *argv [])
{
    int
        argn;                           /*  Argument number                  */
    Bool
        args_ok = TRUE,                 /*  Were the arguments okay?         */
        quiet_mode = FALSE;             /*  -q means suppress messages       */
    char
        *workdir,                       /*  Working directory                */
        *rootdir,                       /*  Default root directory           */
        *cgidir,                        /*  CGI program directory            */
        *ftproot,                       /*  Default FTP root directory       */
        *portbase,                      /*  Value for IP portbase            */
        *background,                    /*  -s means run in background       */
        **argparm;                      /*  Argument parameter to pick-up    */

    /*  First off, switch to user's id                                       */
    set_uid_user ();

    /*  These are the arguments we may get on the command line               */
    workdir    = NULL;
    rootdir    = NULL;
    cgidir     = NULL;
    portbase   = NULL;
    background = NULL;
    ftproot    = NULL;

    argparm = NULL;                     /*  Argument parameter to pick-up    */
    for (argn = 1; argn < argc; argn++)
      {
        /*  If argparm is set, we have to collect an argument parameter      */
        if (argparm)
          {
            if (*argv [argn] != '-')    /*  Parameter can't start with '-'   */
              {
                *argparm = strdupl (argv [argn]);
                argparm = NULL;
              }
            else
              {
                args_ok = FALSE;
                break;
              }
          }
        else
        if (*argv [argn] == '-')
          {
            switch (argv [argn][1])
              {
                /*  These switches take a parameter                          */
                case 'w':
                    argparm = &workdir;  break;
                case 'r':
                    argparm = &rootdir;  break;
                case 'c':
                    argparm = &cgidir;   break;
                case 'b':
                    argparm = &portbase; break;
                case 'f':
                    argparm = &ftproot;  break;

                /*  These switches have an immediate effect                  */
                case 'q':
                    quiet_mode = TRUE;
                    break;
                case 's':
                    background = "1";
                    break;
                case 'S':
                    background = "0";
                    break;
                case 't':
                    smtsock_trace (TRUE);
                    break;
                case 'v':
                    coprintf (PRODUCT);
                    coprintf (BUILDMODEL);
                    coprintf (COPYRIGHT);
                    coprintf ("Built on: %s", BUILDDATE);
                    exit (EXIT_SUCCESS);
                case 'h':
                    coprintf (SERVER_NAME);
                    coprintf (COPYRIGHT);
                    coprintf (USAGE);
                    exit (EXIT_SUCCESS);

                /*  Anything else is an error                                */
                default:
                    args_ok = FALSE;
              }
          }
        else
          {
            args_ok = FALSE;
            break;
          }
      }

    /*  If there was a missing parameter or an argument error, quit          */
    if (argparm)
      {
        puts ("Argument missing - type 'xitami -h' for help");
        exit (EXIT_FAILURE);
      }
    else
    if (!args_ok)
      {
        puts ("Invalid arguments - type 'xitami -h' for help");
        exit (EXIT_FAILURE);
      }
      
    /*  Set server working directory if necessary                            */
    if (workdir
    &&  set_curdir (workdir))
      {
        printf ("Can't work in '%s' - %s\n", workdir, strerror (errno));
        exit (EXIT_FAILURE);
      }

    /*  Load configuration data, if any, into the config_table               */
    config = ini_dyn_load (NULL, "xitami.cfg");
    ini_dyn_load (config, CONFIG ("server:defaults"));

    /*  Initialise arguments, taking defaults from the config_table          */
    if (!rootdir)
        rootdir    = CONFIG ("server:webpages");
    if (!cgidir)
        cgidir     = CONFIG ("server:cgi-bin");
    if (!portbase)
        portbase   = CONFIG ("server:portbase");
    if (!background)
        background = CONFIG ("server:background");
    if (!ftproot)
        ftproot    = CONFIG ("ftp:root");

    /*  Now, handle the remaining arguments we got                           */
    ip_portbase = atoi (portbase);
    if (quiet_mode)
      {
        fclose (stdout);                /*  Kill standard output             */
        fclose (stderr);                /*   and standard error              */
      }
    else
      {
        puts (SERVER_NAME);
        puts (COPYRIGHT);
      }

    if (*background == '1')
      {
        const char
           *background_args [] = { "-s", NULL };

        puts ("Moving into the background");
        if (process_server (NULL, NULL, argc, argv, background_args) != 0)
          {
            puts ("Backgrounding failed.  Giving up.");
            exit (EXIT_FAILURE);
          }
      }

    /*  Initialise the SMT kernel                                            */
    smt_init ();
    server_name = "Xitami";

    /*  Load the agents we want to use                                       */
    if (*CONFIG ("lrwp:enabled") == '1')
        xilrwp_init ();                 /*  LRWP service agent               */
    if (*CONFIG ("security:admin") == '1')
        xiadmin_init ();                /*  Administration agent             */
    if (*CONFIG ("server:supervisor") == '1')
        xisuper_init ();                /*  Supervisor agent                 */
    xierror_init ();                    /*  Error-simulation agent           */
    xiredir_init ();                    /*  Redirection agent                */
    xiddns_init ();                     /*  Dynamic DNS registration         */
    xiimap_init ();                     /*  Image mapping agent              */
    xixlog_init ();                     /*  Extended logging agent           */
    xixssi_init ();                     /*  Internal SSI processor           */
    xixxml_init ();                     /*  Internal XML processor           */
    smthttp_init (rootdir, cgidir);     /*  HTTP agent, required             */
    smtftpc_init (ftproot);             /*  FTP service agent                */
    smtpipe_init (CONFIG ("server:pipedef"));  /*  Transfer pipe agent       */

    smt_exec_full ();                   /*  Run SMT until completed          */
    smt_term ();

    /*  Deallocate configuration symbol table                                */
    sym_delete_table (config);

    /*  Check that all memory was cleanly released                           */
    mem_assert ();

    return (EXIT_SUCCESS);
}
Beispiel #30
0
MODULE display_invalid_argument (THREAD *thread)
{
    tcb = thread-> tcb;                 /*  Point to thread's context        */
    coprintf ("%s: ERROR, invalid argument");
}