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 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!--Converted with LaTeX2HTML 99.2beta8 (1.46)
original version by: Nikos Drakos, CBLU, University of Leeds
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>33. Sending Faxes</TITLE>
<META NAME="description" CONTENT="33. Sending Faxes">
<META NAME="keywords" CONTENT="rute">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="LaTeX2HTML v99.2beta8">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="rute.css">
<LINK REL="next" HREF="node37.html">
<LINK REL="previous" HREF="node35.html">
<LINK REL="up" HREF="rute.html">
<LINK REL="next" HREF="node37.html">
</HEAD>
<BODY BGCOLOR=#FFFFFF >
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
<TR><TD align=left bgcolor="#000000">
<FONT COLOR=white>
<A HREF="http://www.icon.co.za/~psheer/rute-purchase.html"><FONT COLOR=white>Purchase</FONT></A>
</FONT>
</TD><TD align=center bgcolor="#000000">
<FONT COLOR=white>
Copyright © 2002 Paul Sheer. <A HREF="copying.html"><FONT COLOR=white>Click here for copying permissions.</FONT></A>
</FONT>
</TD><TD align=right bgcolor="#000000">
<FONT COLOR=white>
<A HREF="http://www.icon.co.za/~psheer/rute-home.html"><FONT COLOR=white>Home</FONT></A>
</FONT>
</TD></TR>
<TR><TD colspan=2 align=left bgcolor="#ECEBF4">
<IMG SRC="va-btn-small-light-60.png">
</TD><TD align=right bgcolor="#ECEBF4">
<IMG SRC="sflogo2-steel-60.png">
</TD></TR>
</TABLE><BR>
<!--Navigation Panel-->
<A NAME="tex2html2456"
HREF="node37.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
<A NAME="tex2html2452"
HREF="rute.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
<A NAME="tex2html2446"
HREF="node35.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
<A NAME="tex2html2454"
HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html2457"
HREF="node37.html">34. uucp and uux</A>
<B> Up:</B> <A NAME="tex2html2453"
HREF="rute.html">rute</A>
<B> Previous:</B> <A NAME="tex2html2447"
HREF="node35.html">32. init, ? getty,</A>
  <B> <A NAME="tex2html2455"
HREF="node1.html">Contents</A></B>
<BR>
<BR>
<!--End of Navigation Panel-->
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
<UL>
<LI><A NAME="tex2html2458"
HREF="#SECTION003610000000000000000">33.1 Fax Through Printing</A>
<LI><A NAME="tex2html2459"
HREF="#SECTION003620000000000000000">33.2 Setgid Wrapper Binary</A>
</UL>
<!--End of Table of Child-Links-->
<HR>
<H1><A NAME="SECTION003600000000000000000">
33. Sending Faxes</A>
</H1>
<P>
<A NAME="chap:sendingfaxes"></A>
<P>
This chapter discusses the <TT>
<FONT COLOR="#0000ff">sendfax</FONT></TT> program, with reference to the
specific example of setting up an artificial printer that will automatically use a
modem to send its print jobs to remote fax machines.
<P>
<H1><A NAME="SECTION003610000000000000000">
33.1 Fax Through Printing</A>
</H1>
<P>
<I>Continuing from Section <A HREF="node24.html#sec:printtononprinter">21.10</A>...</I>
<P>
You should go now and read the <TT>
<FONT COLOR="#0000ff">sendfax</FONT></TT> section of the <TT>
<FONT COLOR="#0000ff">info</FONT></TT> page
for <TT>
<FONT COLOR="#0000ff">mgetty</FONT></TT>. The <TT>
<FONT COLOR="#0000ff">sendfax</FONT></TT> command is just one program that
sends faxes through the modem. Like <TT>
<FONT COLOR="#0000ff">mgetty</FONT></TT>, it reads a config file
in <TT>
<FONT COLOR="#0000ff">/etc/mgetty+sendfax/</FONT></TT>. This
config file is just <TT>
<FONT COLOR="#0000ff">sendfax.config</FONT></TT>
and can contain as little as
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>verbose y</code><br>
<code>debug 5</code><br>
<code>fax-devices ttyS0</code><br>
<code>fax-id 27 21 7654321</code><br>
<code>max-tries 3</code><br>
<code>max-tries-continue y</code><br>
</FONT></TD></TR></TABLE><P>
<P>
Below, <TT>
<FONT COLOR="#0000ff">fax_filter.sh</FONT></TT>
is a script that sends the print job
through the fax machine after requesting the telephone number through
<TT>
<FONT COLOR="#0000ff">gdialog</FONT></TT>. <FONT COLOR="#ffa500">[<TT>
<FONT COLOR="#0000ff">gdialog</FONT></TT> is part of the <TT>
<FONT COLOR="#0000ff">gnome-utils</FONT></TT>
package.]</FONT> An appropriate <TT>
<FONT COLOR="#0000ff">/etc/printcap</FONT></TT> entry is:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>fax:\</code><br>
<code> :sd=/var/spool/lpd/fax:\</code><br>
<code> :mx#0:\</code><br>
<code> :sh:\</code><br>
<code> :lp=/dev/null:\</code><br>
<code> :if=/var/spool/lpd/fax/fax_filter.sh:</code><br>
</FONT></TD></TR></TABLE><P>
<P>
The file <TT>
<FONT COLOR="#0000ff">fax_filter.sh</FONT></TT> itself could contain a script like
this <FONT COLOR="#ffa500">[Remember to rotate the
<TT>
<FONT COLOR="#0000ff">/var/log/fax</FONT></TT> log file, see page
<A HREF="node24.html#sec:logrotation"><IMG ALIGN="BOTTOM" BORDER="1" ALT="[*]" SRC="crossref.png"></A>.]</FONT> for a modem on
<TT>
<FONT COLOR="#0000ff">/dev/ttyS0</FONT></TT>:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>10</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>15</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>20</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>25</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>30</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>35</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>40</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>45</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>50</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>55</code></font><code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>#!/bin/sh</code><br>
<code> </code><br>
<code>exec 1>>/var/log/fax</code><br>
<code>exec 2>>/var/log/fax</code><br>
<code> </code><br>
<code>echo</code><br>
<code>echo</code><br>
<code>echo $@</code><br>
<code> </code><br>
<code>echo "Starting fax `date`: I am `id`"</code><br>
<code> </code><br>
<code>export DISPLAY=localhost:0.0</code><br>
<code>export HOME=/home/lp</code><br>
<code> </code><br>
<code>function error()</code><br>
<code>{</code><br>
<code> gdialog --title "Send Fax" --msgbox "$1" 10 75 || \</code><br>
<code> echo 'Huh? no gdialog on this machine'</code><br>
<code> cd /</code><br>
<code> rm -Rf /tmp/$$fax || \</code><br>
<code> gdialog \</code><br>
<code> --title "Send Fax" \</code><br>
<code> --msgbox "rm -Rf /tmp/$$fax failed" \</code><br>
<code> 10 75</code><br>
<code> exit 1</code><br>
<code>}</code><br>
<code> </code><br>
<code>mkdir /tmp/$$fax || error "mkdir /tmp/$$fax failed"</code><br>
<code>cd /tmp/$$fax || error "cd /tmp/$$fax failed"</code><br>
<code> </code><br>
<code>cat > fax.ps</code><br>
<code> </code><br>
<code>if /usr/bin/gdialog \</code><br>
<code> --title "Send Fax" \</code><br>
<code> --inputbox "Enter the phone number to fax:" \</code><br>
<code> 10 75 "" 2>TEL ; then</code><br>
<code> :</code><br>
<code>else</code><br>
<code> echo "gdialog failed `< TEL`"</code><br>
<code> rm -Rf /tmp/$$fax</code><br>
<code> exit 0</code><br>
<code>fi</code><br>
<code> </code><br>
<code>TEL=`< TEL`</code><br>
<code>test -z "$TEL" && error 'no telephone number given'</code><br>
<code> </code><br>
<code>cat fax.ps | gs -r204x98 -sOutputFile=- -sDEVICE=faxg3 -dBATCH -q - \</code><br>
<code> 1>fax.ps.g3 || error 'gs failed'</code><br>
<code> </code><br>
<code>ls -al /var/lock/</code><br>
<code>/usr/sbin/sendfax -x 5 -n -l ttyS0 $TEL fax.ps.g3 || \</code><br>
<code> error "sendfax failed"</code><br>
<code> </code><br>
<code>rm -Rf /tmp/$$fax</code><br>
<code> </code><br>
<code>exit 0</code><br>
</FONT></TD></TR></TABLE><P>
<P>
<H1><A NAME="SECTION003620000000000000000">
33.2 Setgid Wrapper Binary</A>
</H1>
<P>
<A NAME="sec:faxsetuidbin"></A>
<P>
The above script is not enough however. Above, <TT>
<FONT COLOR="#0000ff">sendfax</FONT></TT> requires access to the
<TT>
<FONT COLOR="#0000ff">/dev/ttyS0</FONT></TT> device as well as the
<TT>
<FONT COLOR="#0000ff">/var/lock/</FONT></TT> directory (to
create a modem lock file--see Section <A HREF="node37.html#sec:ttylockfile">34.4</A>). It cannot do
that as the <TT>
<FONT COLOR="#0000ff">lp</FONT></TT> user (under which the above filter runs).
On RedHat, the command <TT>
<FONT COLOR="#0000ff">ls -ald /var/lock /dev/ttyS0</FONT></TT> reveals that only
<TT>
<FONT COLOR="#0000ff">uucp</FONT></TT> is allowed to access modems.
We can get around this restriction
by creating a setgid
(see Chapter <A HREF="node17.html#chap:permmodtimes">14</A>) binary that runs as the
<TT>
<FONT COLOR="#0000ff">uucp</FONT></TT> user. Do this by compiling the <B>C</B> program,
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red size="-1">
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-2"><code>5</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-2"><code>10</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-2"><code>15</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-2"><code>20</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-2"><code>25</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-2"><code>30</code></font><code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue size="-1">
<code>#include <stdlib.h></code><br>
<code>#include <string.h></code><br>
<code>#include <stdio.h></code><br>
<code>#include <unistd.h></code><br>
<code> </code><br>
<code>int main (int argc, char **argv)</code><br>
<code>{</code><br>
<code> char **a;</code><br>
<code> int i;</code><br>
<code> </code><br>
<code>/* set the real group ID to that of the effective group ID */</code><br>
<code> if (setgid (getegid ())) {</code><br>
<code> perror ("sendfax_wrapper: setgid failed");</code><br>
<code> exit (1);</code><br>
<code> }</code><br>
<code> </code><br>
<code>/* copy all arguments */</code><br>
<code> a = (char **) malloc ((argc + 1) * sizeof (char *));</code><br>
<code> for (i = 1; i < argc; i++)</code><br>
<code> a[i] = (char *) strdup (argv[i]);</code><br>
<code> a[argc] = NULL;</code><br>
<code> </code><br>
<code>/* execute sendfax */</code><br>
<code> a[0] = "/usr/sbin/sendfax";</code><br>
<code> execvp (a[0], a);</code><br>
<code> </code><br>
<code>/* exit on failure */</code><br>
<code> perror ("sendfax_wrapper: failed to exececute /usr/sbin/sendfax");</code><br>
<code> exit (1);</code><br>
<code>}</code><br>
</FONT></TD></TR></TABLE><P>
using the commands,
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>gcc sendfax_wrapper.c -o /usr/sbin/sendfax_wrapper -Wall</code><br>
<code>chown lp:uucp /usr/sbin/sendfax_wrapper</code><br>
<code>chmod g+s,o-rwx /usr/sbin/sendfax_wrapper</code><br>
</FONT></TD></TR></TABLE><P>
Then, replace
<TT>
<FONT COLOR="#0000ff">sendfax</FONT></TT> with <TT>
<FONT COLOR="#0000ff">sendfax_wrapper</FONT></TT> in the filter script. You can
see that <TT>
<FONT COLOR="#0000ff">sendfax_wrapper</FONT></TT> just executes <TT>
<FONT COLOR="#0000ff">sendfax</FONT></TT> after changing
the group ID to the <I>effective group ID</I> (GID) as obtained from the <TT>
<FONT COLOR="#0000ff">getegid</FONT></TT>
function on line 12. The effective group ID is <TT>
<FONT COLOR="#0000ff">uucp</FONT></TT> because of the
setgid group bit (i.e., <TT>
<FONT COLOR="#0000ff">g+s</FONT></TT>) in the
<TT>
<FONT COLOR="#0000ff">chmod</FONT></TT> command, and hence
<TT>
<FONT COLOR="#0000ff">sendfax</FONT></TT> runs under the <TT>
<FONT COLOR="#0000ff">uucp</FONT></TT> group with full access to the modem
device.
<P>
On your own system it may be cleaner to try implement this without a
wrapper. Debian, for example, has a <TT>
<FONT COLOR="#0000ff">dialout</FONT></TT> group for the
purposes of accessing modems. Also be aware that some distributions may
not use the <TT>
<FONT COLOR="#0000ff">uucp</FONT></TT> user in the way RedHat does and you may have to
create an alternative user especially for this task.
<P>
<P>
<HR>
<!--Navigation Panel-->
<A NAME="tex2html2456"
HREF="node37.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
<A NAME="tex2html2452"
HREF="rute.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
<A NAME="tex2html2446"
HREF="node35.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
<A NAME="tex2html2454"
HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html2457"
HREF="node37.html">34. uucp and uux</A>
<B> Up:</B> <A NAME="tex2html2453"
HREF="rute.html">rute</A>
<B> Previous:</B> <A NAME="tex2html2447"
HREF="node35.html">32. init, ? getty,</A>
  <B> <A NAME="tex2html2455"
HREF="node1.html">Contents</A></B>
<!--End of Navigation Panel-->
</BODY>
</HTML>
|