1 /* ***********************************************************
 2    *                                                         *
 3    * Copyright, (C) Honeywell Bull Inc., 1987                *
 4    *                                                         *
 5    * Copyright, (C) Honeywell Information Systems Inc., 1986 *
 6    *                                                         *
 7    *********************************************************** */
 8 
 9 /* HISTORY COMMENTS:
10   1) change(86-02-24,ASmith), approve(87-07-13,MCR7580),
11      audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
12      Created.
13   2) change(86-06-05,Westcott), approve(87-07-13,MCR7580),
14      audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
15      Support for execom structure.
16                                                    END HISTORY COMMENTS */
17 
18 /* : PROCEDURE FUNCTION (EXECUTE_COMMAND)
19 
20 This Internal MOWSE software interrupt handler executes a command (included
21 in a message) sent from some remote system.  Errors encountered in processing
22 the command are sent back to a specified capability.
23 */
24 
25 /* : NOTES
26 */
27 
28 #include <stdio.h>
29 #include <ws.h>
30 #include <wsmincap.h>
31 #include <ws_error.h>
32 #include <ws_msg.h>
33 
34 #define STATUS_SUCCESS 32
35 #define STATUS_FAILED 33
36 
37 extern char mysystem;
38 
39 EXECUTE_COMMAND(com_len,execmp)
40 
41 int     com_len;                /* Length of message */
42 struct execom_msg *execmp;      /* Execute command message */
43 {
44 int error;
45 char *cmd;                      /* pointer to command string */
46 struct exerep_msg exerep;       /* reply message */
47 struct execom_msg *execmd;      /* pointer to execute command message */
48 
49 
50 /* : Try to execute command locally. */
51 
52    cmd = &execmp->command[0];
53    com_len = com_len - sizeof(struct execom_msg) + 1;
54    cmd[com_len] = '\0';         /* ensure command ends with zero byte */
55    set_dta();                   /* use Mowse's DTA */
56    set_trap();                  /* use MOWSE's trap rotuines */
57    error = system(cmd);
58    rst_trap();
59    rst_dta();
60 
61 /* : If execution failed then formulate message_1 to send to err_handler. */
62 
63    if (error)
64       exerep.status = (char) STATUS_FAILED;
65    else
66       exerep.status = STATUS_SUCCESS;
67 
68 /* : Send the reply to the source of the request */
69 
70    exerep.system = execmp->source_system;
71    exerep.major = execmp->source_major;
72    exerep.minor = EXECUTE_COMMAND_REPLY;
73    exerep.source_major = WSMAJCAP;
74    exerep.source_system = mysystem;
75    exerep.cmd_id = execmp->cmd_id;
76 
77    send_i_mess(&exerep.system,sizeof(exerep),NULL,0);
78 }
79 /* : END */
80 ^Z