summaryrefslogtreecommitdiff
path: root/doc/manpage.d/ipsec_optionsfrom.3.html
blob: 05d045e4d8165befcb34c02731bca64718c0fb99 (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
Content-type: text/html

<HTML><HEAD><TITLE>Manpage of IPSEC_OPTIONSFROM</TITLE>
</HEAD><BODY>
<H1>IPSEC_OPTIONSFROM</H1>
Section: C Library Functions (3)<BR>Updated: 16 Oct 1998<BR><A HREF="#index">Index</A>
<A HREF="http://localhost/cgi-bin/man/man2html">Return to Main Contents</A><HR>


<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>

ipsec optionsfrom - read additional ``command-line'' options from file
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>

<B>#include &lt;<A HREF="file:/usr/include/freeswan.h">freeswan.h</A>&gt;</B>

<P>
<B>const char *optionsfrom(char *filename, int *argcp,</B>

<BR>
&nbsp;
<B>char ***argvp, int optind, FILE *errsto);</B>

<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>

<I>Optionsfrom</I>

is called from within a
<I><A HREF="getopt_long.3.html">getopt_long</A></I>(3)

scan,
as the result of the appearance of an option (preferably
<B>--optionsfrom</B>)

to insert additional ``command-line'' arguments
into the scan immediately after
the option.
Typically this would be done to pick up options which are
security-sensitive and should not be visible to
<I><A HREF="ps.1.html">ps</A></I>(1)

and similar commands,
and hence cannot be supplied as part
of the actual command line or the environment.
<P>

<I>Optionsfrom</I>

reads the additional arguments from the specified
<I>filename</I>,

allocates a new argument vector to hold pointers to the existing
arguments plus the new ones,
and amends
<I>argc</I>

and
<I>argv</I>

(via the pointers
<I>argcp</I>

and
<I>argvp</I>,

which must point to the
<I>argc</I>

and
<I>argv</I>

being supplied to
<I><A HREF="getopt_long.3.html">getopt_long</A></I>(3))

accordingly.
<I>Optind</I>

must be the index, in the original argument vector,
of the next argument.
<P>

If
<I>errsto</I>

is NULL,
<I>optionsfrom</I>

returns NULL for success and
a pointer to a string-literal error message for failure;
see DIAGNOSTICS.
If
<I>errsto</I>

is non-NULL and an error occurs,
<I>optionsfrom</I>

prints a suitable complaint onto the
<I>errsto</I>

descriptor and invokes
<I>exit</I>

with an exit status of 2;
this is a convenience for cases where more sophisticated
responses are not required.
<P>

The text of existing arguments is not disturbed by
<I>optionsfrom</I>,

so pointers to them and into them remain valid.
<P>

The file of additional arguments is an ASCII text file.
Lines consisting solely of white space,
and lines beginning with
<B>#</B>,

are comments and are ignored.
Otherwise, a line which does not begin with
<B>-</B>

is taken to be a single argument;
if it both begins and ends with double-quote (&quot;),
those quotes are stripped off (note, no other processing is done within
the line!).
A line beginning with
<B>-</B>

is considered to contain multiple arguments separated by white space.
<P>

Because
<I>optionsfrom</I>

reads its entire file before the
<I><A HREF="getopt_long.3.html">getopt_long</A></I>(3)

scan is resumed, an
<I>optionsfrom</I>

file can contain another
<B>--optionsfrom</B>

option.
Obviously, infinite loops are possible here.
If
<I>errsto</I>

is non-NULL,
<I>optionsfrom</I>

considers it an error to be called more than 100 times.
If
<I>errsto</I>

is NULL,
loop detection is up to the caller
(and the internal loop counter is zeroed out).
<A NAME="lbAE">&nbsp;</A>
<H2>EXAMPLE</H2>

A reasonable way to invoke
<I>optionsfrom</I>

would be like so:
<P>

<PRE>
<B>#include &lt;<A HREF="file:/usr/include/getopt.h">getopt.h</A>&gt;

struct option opts[] = {
        /* ... */
        &quot;optionsfrom&quot;,  1,      NULL,   '+',
        /* ... */
};

int
main(argc, argv)
int argc;
char *argv[];
{
        int opt;
        extern char *optarg;
        extern int optind;

        while ((opt = getopt_long(argc, argv, &quot;&quot;, opts, NULL)) != EOF)
                switch (opt) {
                /* ... */
                case '+':       /* optionsfrom */
                        optionsfrom(optarg, &amp;argc, &amp;argv, optind, stderr);
                        /* does not return on error */
                        break;
                /* ... */
                }
        /* ... */
</B></PRE>

<A NAME="lbAF">&nbsp;</A>
<H2>SEE ALSO</H2>

<A HREF="getopt_long.3.html">getopt_long</A>(3)
<A NAME="lbAG">&nbsp;</A>
<H2>DIAGNOSTICS</H2>

Errors in
<I>optionsfrom</I>

are:
unable to open file;
attempt to allocate temporary storage for argument or
argument vector failed;
read error in file;
line too long.
<A NAME="lbAH">&nbsp;</A>
<H2>HISTORY</H2>

Written for the FreeS/WAN project by Henry Spencer.
<A NAME="lbAI">&nbsp;</A>
<H2>BUGS</H2>

The double-quote convention is rather simplistic.
<P>

Line length is currently limited to 1023 bytes,
and there is no continuation convention.
<P>

The restriction of error reports to literal strings
(so that callers don't need to worry about freeing them or copying them)
does limit the precision of error reporting.
<P>

The error-reporting convention lends itself
to slightly obscure code,
because many readers will not think of NULL as signifying success.
<P>

There is a certain element of unwarranted chumminess with
the insides of
<I><A HREF="getopt_long.3.html">getopt_long</A></I>(3)

here.
No non-public interfaces are actually used, but
<I>optionsfrom</I>

does rely on
<I><A HREF="getopt_long.3.html">getopt_long</A></I>(3)

being well-behaved in certain ways that are not actually
promised by the specs.
<P>

<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT><A HREF="#lbAE">EXAMPLE</A><DD>
<DT><A HREF="#lbAF">SEE ALSO</A><DD>
<DT><A HREF="#lbAG">DIAGNOSTICS</A><DD>
<DT><A HREF="#lbAH">HISTORY</A><DD>
<DT><A HREF="#lbAI">BUGS</A><DD>
</DL>
<HR>
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 21:40:18 GMT, November 11, 2003
</BODY>
</HTML>