summaryrefslogtreecommitdiffstats
path: root/include/sh_extern.h
blob: 64a0a99b3242b379ece946fd318efed79c2aee0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef SH_EXTERN_H
#define SH_EXTERN_H

#include <stdarg.h>

typedef struct 
{
  char   *  command;
  int       argc;
  char   *  argv[32];
  int       envc;
  char   *  envv[32];
  char      checksum[KEY_LEN + 1];
#if 0
  uid_t     trusted_users[32];
#endif
  uid_t     run_user_uid;
  gid_t     run_user_gid;
  int       privileged;

  int       pipeFD;
  SL_TICKET pipeTI;
  pid_t     pid;
  FILE   *  pipe;
  char      rw;
  int       exit_status;
  int       fork_twice;

  int       com_fd;
  SL_TICKET com_ti;

} sh_tas_t;


/*
 * -- generic safe popen; returns 0 on success, -1 otherwise
 */
int sh_ext_popen (sh_tas_t * task);

/*
 * -- generic simple safe popen; returns 0 on success, -1 otherwise,
 *    executes shell command
 */
int sh_ext_popen_init (sh_tas_t * task, const char * command, char * argv0, ...) SH_GNUC_SENTINEL;

/*
 * -- Execute command, return first line of output
 */
int sh_ext_system (char * command, char * argv0, ...) SH_GNUC_SENTINEL;

/*
 * -- Execute command, return first line of output
 */
char * sh_ext_popen_str (const char * command);

/*
 * -- close the pipe, clear and return task->exit_status
 */
int sh_ext_pclose (sh_tas_t * task);

/*
 * -- add CL argument, return # of arguments
 */
int sh_ext_tas_add_argv(sh_tas_t * tas, const char * val);
/*
 * -- remove last CL argument
 */
int sh_ext_tas_rm_argv(sh_tas_t * tas);
/*
 * -- add environment variable, return # of variables
 */
int sh_ext_tas_add_envv(sh_tas_t * tas, const char * key, const char * val);
/*
 * -- set command
 */
void sh_ext_tas_command(sh_tas_t * tas, const char * command);
/*
 * -- initialize task structure
 */
void sh_ext_tas_init (sh_tas_t * tas);
/*
 * -- free task structure
 */
void sh_ext_tas_free(sh_tas_t * tas);


#if defined(WITH_EXTERNAL)

/* 
 * -- start a new external command, and add it to the list
 */ 
int sh_ext_setcommand(const char * cmd);

/*
 * -- explicitely close a command
 */
int sh_ext_close_command (const char * str);

/* 
 * -- clean up the command list
 */
int sh_ext_cleanup(void);

/*
 * -- set deadtime
 */
int sh_ext_deadtime (const char * str);

/*
 * -- add keywords to the OR filter
 */
int sh_ext_add_or (const char * str);

/*
 * -- add keywords to the AND filter
 */
int sh_ext_add_and (const char * str);

/*
 * -- add keywords to the NOT filter
 */
int sh_ext_add_not (const char * str);

/*
 * -- add keywords to the CL argument list
 */
int sh_ext_add_argv (const char * str);

/*
 * -- add a path to the environment
 */
int sh_ext_add_default (const char * str);

/*
 * -- add an environment variable
 */
int sh_ext_add_environ (const char * str);

/*
 * -- define type
 */
int sh_ext_type (const char * str);

/*
 * -- define checksum
 */
int sh_ext_checksum (const char * str);

/*
 * -- choose privileges
 */
int sh_ext_priv (const char * c);

/*
 * -- execute external script/program
 */
int sh_ext_execute (char t1, char t2, char t3, /*@null@*/char * message, 
		    size_t msg_siz);

#endif

#endif