]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - gnu/libexec/uucp/common_sources/system.h
This commit was generated by cvs2svn to compensate for changes in r52279,
[FreeBSD/FreeBSD.git] / gnu / libexec / uucp / common_sources / system.h
1 /* system.h
2    Header file for system dependent stuff in the Taylor UUCP package.
3    This file is not itself system dependent.
4
5    Copyright (C) 1991, 1992, 1993, 1994, 1995 Ian Lance Taylor
6
7    This file is part of the Taylor UUCP package.
8
9    This program is free software; you can redistribute it and/or
10    modify it under the terms of the GNU General Public License as
11    published by the Free Software Foundation; either version 2 of the
12    License, or (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful, but
15    WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17    General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23    The author of the program may be contacted at ian@airs.com or
24    c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
25    */
26
27 #ifndef SYSTEM_H
28
29 #define SYSTEM_H
30
31 #if ANSI_C
32 /* These structures are used in prototypes but are not defined in this
33    header file.  */
34 struct tm;
35 struct uuconf_system;
36 struct uuconf_port;
37 struct sconnection;
38 struct sstatus;
39 struct scmd;
40 #endif
41
42 /* Any function which returns an error should also report an error
43    message, unless otherwise indicated.
44
45    Any function that returns a char *, rather than a const char *, is
46    returning a pointer to a buffer allocated by zbufalc which must be
47    freed using ubuffree, unless otherwise indicated.  */
48
49 /* The maximum length of a remote system name.  */
50 extern size_t cSysdep_max_name_len;
51
52 /* Initialize.  If something goes wrong, this routine should just
53    exit.  The flag argument is 0, or a combination of any of the
54    following flags.  */
55
56 /* This program needs to know the current working directory.  This is
57    used because on Unix it can be expensive to determine the current
58    working directory (some versions of getcwd fork a process), but in
59    most cases we don't need to know it.  However, we are going to
60    chdir to the spool directory (unless INIT_CHDIR is set), so we have
61    to get the cwd now if we are ever going to get it.  Both uucp and
62    uux use the function fsysdep_needs_cwd to determine whether they
63    will need the current working directory, and pass the argument to
64    usysdep_initialize appropriately.  There's probably a cleaner way
65    to handle this, but this will suffice for now.  */
66 #define INIT_GETCWD (01)
67
68 /* This program should not chdir to the spool directory.  This may
69    only make sense on Unix.  It is set by cu.  */
70 #define INIT_NOCHDIR (02)
71
72 /* This program needs special access to the spool directories.  That
73    means, on Unix, this program is normally installed setuid.  */
74 #define INIT_SUID (04)
75
76 /* Do not close all open descriptors.  This is not used by the UUCP
77    code, but it is used by other programs which share some of the
78    system dependent libraries.  */
79 #define INIT_NOCLOSE (010)
80
81 extern void usysdep_initialize P((pointer puuconf, int iflags));
82
83 /* Exit the program.  The fsuccess argument indicates whether to
84    return an indication of success or failure to the outer
85    environment.  This routine should not return.  */
86 extern void usysdep_exit P((boolean fsuccess));
87
88 /* Called when a non-standard configuration file is being used, to
89    avoid handing out privileged access.  If it returns FALSE, default
90    configuration file will be used.  This is called before the
91    usysdep_initialize function is called.  */
92 extern boolean fsysdep_other_config P((const char *));
93
94 /* Detach from the controlling terminal.  This probably only makes
95    sense on Unix.  It is called by uucico to try to get the modem port
96    as a controlling terminal.  It is also called by uucico before it
97    starts up uuxqt, so that uuxqt will be a complete daemon.  */
98 extern void usysdep_detach P((void));
99
100 /* Get the local node name if it is not specified in the configuration
101    files.  Returns NULL on error; otherwise the return value should
102    point to a static buffer.  */
103 extern const char *zsysdep_localname P((void));
104
105 /* Get the login name.  This is used when uucico is started up with no
106    arguments in slave mode, which causes it to assume that somebody
107    has logged in.  It also used by uucp and uux for recording the user
108    name.  This may not return NULL.  The return value should point to
109    a static buffer.  */
110 extern const char *zsysdep_login_name P((void));
111
112 /* Set a signal handler for a signal.  If the signal occurs, the
113    appropriate element of afSignal should be set to the signal number
114    (see the declaration of afSignal in uucp.h).  This routine might be
115    able to just use signal, but Unix requires more complex handling.
116    This is called before usysdep_initialize.  */
117 extern void usysdep_signal P((int isig));
118
119 /* Catch a signal.  This is actually defined as a macro in the system
120    dependent header file, and the prototype here just indicates how it
121    should be called.  It is called before a routine which must exit if
122    a signal occurs, and is expected to set do a setjmp (which is why
123    it must be a macro).  It is actually only called in one place in
124    the system independent code, before the call to read stdin in uux.
125    This is needed to handle 4.2 BSD restartable system calls, which
126    require a longjmp.  On systems which don't need to do
127    setjmp/longjmp around system calls, this can be redefined in
128    sysdep.h to TRUE.  It should return TRUE if the routine should
129    proceed, or FALSE if a signal occurred.  After having this return
130    TRUE, usysdep_start_catch should be used to start catching the
131    signal; this basically tells the signal handler that it's OK to do
132    the longjmp, if fsysdep_catch did not already do so.  */
133 #ifndef fsysdep_catch
134 extern boolean fsysdep_catch P((void));
135 #endif
136
137 /* Start catching a signal.  This is called after fsysdep_catch to
138    tell the signal handler to go ahead and do the longjmp.  This may
139    be implemented as a macro in sysdep.h.  */
140 #ifndef usysdep_start_catch
141 extern void usysdep_start_catch P((void));
142 #endif
143
144 /* Stop catching a signal.  This is called when it is no longer
145    necessary for fsysdep_catch to handle signals.  This may be
146    implemented as a macro in sysdep.h.  */
147 #ifndef usysdep_end_catch
148 extern void usysdep_end_catch P((void));
149 #endif
150
151 /* Link two files.  On Unix this should attempt the link.  If it
152    succeeds it should return TRUE with *pfworked set to TRUE.  If the
153    link fails because it must go across a device, it should return
154    TRUE with *pfworked set to FALSE.  If the link fails for some other
155    reason, it should log an error message and return FALSE.  On a
156    system which does not support links to files, this should just
157    return TRUE with *pfworked set to FALSE.  */
158 extern boolean fsysdep_link P((const char *zfrom, const char *zto,
159                                boolean *pfworked));
160
161 /* Get the port name.  This is used when uucico is started up in slave
162    mode to figure out which port was used to call in so that it can
163    determine any appropriate protocol parameters.  This may return
164    NULL if the port cannot be determined, which will just mean that no
165    protocol parameters are applied.  The name returned should be the
166    sort of name that would appear in the port file.  This should set
167    *pftcp_port to TRUE if it can determine that the port is a TCP
168    connection rather than a normal serial port.  The return value (if
169    not NULL) should point to a static buffer.  */
170 extern const char *zsysdep_port_name P((boolean *pftcp_port));
171
172 /* Expand a file name on the local system.  On Unix, if the zfile
173    argument begins with ~user/ it goes in that users home directory,
174    and if it begins with ~/ it goes in the public directory (the
175    public directory is passed to this routine, since each system may
176    have its own public directory).  Similar conventions may be
177    desirable on other systems.  This should always return an absolute
178    path name, probably in the public directory.  It should return NULL
179    on error; otherwise the return value should be allocated using
180    zbufcpy or zbufalc.  If pfbadname is not NULL, then if the function
181    returns NULL *pfbadname should be set to TRUE if the error is just
182    that the file name is badly specified; *pfbadname should be set to
183    FALSE for some sort of internal error.  */
184 extern char *zsysdep_local_file P((const char *zname,
185                                    const char *zpubdir,
186                                    boolean *pfbadname));
187
188 /* Return whether a file name is in a directory, and check for read or
189    write access.  This should check whether zfile is within zdir (or
190    is zdir itself).  If it is not, it should return FALSE.  If zfile
191    is in zdir, then fcheck indicates whether further checking should
192    be done.  If fcheck is FALSE, no further checking is done.
193    Otherwise, if freadable is TRUE the user zuser should have search
194    access to all directories from zdir down to zfile and should have
195    read access on zfile itself (if zfile does not exist, or is not a
196    regular file, this function may return FALSE but does not have to).
197    If freadable is FALSE, the user zuser should have search access to
198    all directories from zdir down to zfile and should have write
199    access on zfile (which may be a directory, or may not actually
200    exist, which is acceptable).  The zuser argument may be NULL, in
201    which case the check should be made for any user, not just zuser.
202    There is no way for this function to return error.  */
203 extern boolean fsysdep_in_directory P((const char *zfile,
204                                        const char *zdir,
205                                        boolean fcheck,
206                                        boolean freadable,
207                                        const char *zuser));
208
209 /* Return TRUE if a file exists, FALSE otherwise.  There is no way to
210    return error.  */
211 extern boolean fsysdep_file_exists P((const char *zfile));
212
213 /* Start up a program.  If the ffork argument is true, this should
214    spawn a new process and return.  If the ffork argument is false,
215    this may either return or not.  The three string arguments may be
216    catenated together to form the program to execute; I did it this
217    way to make it easy to call execl(2), and because I never needed
218    more than two arguments.  The program will always be "uucico" or
219    "uuxqt".  The return value should be TRUE on success, FALSE on
220    error.  */
221 extern boolean fsysdep_run P((boolean ffork, const char *zprogram,
222                               const char *zarg1, const char *zarg2));
223
224 /* Send a mail message.  This function will be passed an array of
225    strings.  All necessary newlines are already included; the strings
226    should simply be concatenated together to form the mail message.
227    It should return FALSE on error, although the return value is often
228    ignored.  */
229 extern boolean fsysdep_mail P((const char *zto, const char *zsubject,
230                                int cstrs, const char **paz));
231
232 /* Get the time in seconds since some epoch.  The actual epoch is
233    unimportant, so long as the time values are consistent across
234    program executions and the value is never negative.  If the
235    pimicros argument is not NULL, it should be set to the number of
236    microseconds (if this is not available, *pimicros should be set to
237    zero).  */
238 extern long ixsysdep_time P((long *pimicros));
239
240 /* Get the time in seconds and microseconds (millionths of a second)
241    since some epoch.  The actual epoch is not important, and it may
242    change in between program invocations; this is provided because on
243    Unix the times function may be used.  If microseconds can not be
244    determined, *pimicros can just be set to zero.  */
245 extern long ixsysdep_process_time P((long *pimicros));
246
247 /* Parse the value returned by ixsysdep_time into a struct tm.  I
248    assume that this structure is defined in <time.h>.  This is
249    basically just localtime, except that the ANSI function takes a
250    time_t which may not be what is returned by ixsysdep_time.  */
251 extern void usysdep_localtime P((long itime, struct tm *q));
252
253 /* Sleep for a number of seconds.  */
254 extern void usysdep_sleep P((int cseconds));
255
256 /* Pause for half a second, or 1 second if subsecond sleeps are not
257    possible.  */
258 extern void usysdep_pause P((void));
259 \f
260 /* Lock a remote system.  This should return FALSE if the system is
261    already locked (no error should be reported).  */
262 extern boolean fsysdep_lock_system P((const struct uuconf_system *qsys));
263
264 /* Unlock a remote system.  This should return FALSE on error
265    (although the return value is generally ignored).  */
266 extern boolean fsysdep_unlock_system P((const struct uuconf_system *qsys));
267
268 /* Get the conversation sequence number for a remote system, and
269    increment it for next time.  This should return -1 on error.  */
270 extern long ixsysdep_get_sequence P((const struct uuconf_system *qsys));
271
272 /* Get the status of a remote system.  This should return FALSE on
273    error.  Otherwise it should set *qret to the status.  If no status
274    information is available, this should set *qret to sensible values
275    and return TRUE.  If pfnone is not NULL, then it should be set to
276    TRUE if no status information was available or FALSE otherwise.  */
277 extern boolean fsysdep_get_status P((const struct uuconf_system *qsys,
278                                      struct sstatus *qret,
279                                      boolean *pfnone));
280
281 /* Set the status of a remote system.  This should return FALSE on
282    error.  The system will be locked before this call is made.  */
283 extern boolean fsysdep_set_status P((const struct uuconf_system *qsys,
284                                      const struct sstatus *qset));
285
286 /* See whether a remote system is permitted to log in.  This is just
287    to support the remote.unknown shell script for HDB.  The zscript
288    argument is the script name, as return by uuconf_remote_unknown.
289    The zsystem argument is the name given by the remote system.  If
290    the system is not permitted to log in, this function should log an
291    error and return FALSE.  */
292 extern boolean fsysdep_unknown_caller P((const char *zscript,
293                                          const char *zsystem));
294 \f
295 /* Check whether there is work for a remote system.  It should return
296    TRUE if there is work, FALSE otherwise; there is no way to indicate
297    an error.  */
298 extern boolean fsysdep_has_work P((const struct uuconf_system *qsys));
299
300 /* Initialize the work scan.  This will be called before
301    fsysdep_get_work.  The bgrade argument is the minimum grade of
302    execution files that should be considered (e.g. a bgrade of 'd'
303    will allow all grades from 'A' to 'Z' and 'a' to 'd').  This
304    function should return FALSE on error.  */
305 extern boolean fsysdep_get_work_init P((const struct uuconf_system *qsys,
306                                         int bgrade));
307
308 /* Get the next command to be executed for a remote system.  The
309    bgrade argument will be the same as for fsysdep_get_work_init;
310    probably only one of these functions will use it, namely the
311    function for which it is more convenient.  This should return FALSE
312    on error.  The structure pointed to by qcmd should be filled in.
313    The strings may point into a static buffer; they will be copied out
314    if necessary.  If there is no more work, this should set qcmd->bcmd
315    to 'H' and return TRUE.  This should set qcmd->pseq to something
316    which can be passed to fsysdep_did_work to remove the job from the
317    queue when it has been completed.  This may set qcmd->bcmd to 'P'
318    to represent a poll file; the main code will just pass the pseq
319    element of such a structure to fsysdep_did_work if the system is
320    called.  */
321 extern boolean fsysdep_get_work P((const struct uuconf_system *qsys,
322                                    int bgrade, struct scmd *qcmd));
323
324 /* Remove a job from the work queue.  This must also remove the
325    temporary file used for a send command, if there is one.  It should
326    return FALSE on error.  */
327 extern boolean fsysdep_did_work P((pointer pseq));
328
329 /* Save the temporary file for a send command.  This function should
330    return a string that will be put into a mail message.  On success
331    this string should say something like ``The file has been saved as
332    ...''.  On failure it could say something like ``The file could not
333    be saved because ...''.  If there is no temporary file, or for some
334    reason it's not appropriate to include a message, this function
335    should just return NULL.  This function is used when a file send
336    fails for some reason, to make sure that we don't completely lost
337    the file.  */
338 extern const char *zsysdep_save_temp_file P((pointer pseq));
339
340 /* Save a file in a location used to hold corrupt files.  This is
341    called if a bad execution file is found by uuxqt.  This should
342    return the new name of the file (allocated by zbufalc), or NULL if
343    the move failed (in which the original file should remain).  */
344 extern char *zsysdep_save_corrupt_file P((const char *zfile));
345
346 /* Save a file in a location used to hold failed execution files.
347    This is called if a uuxqt execution fails.  This should return the
348    new name of the file (allocated by zbufalc), or NULL if the move
349    failed (in which case the original file should remain).  */
350 extern char *zsysdep_save_failed_file P((const char *zfile));
351
352 /* Cleanup anything left over by fsysdep_get_work_init and
353    fsysdep_get_work.  This may be called even though
354    fsysdep_get_work_init has not been.  */
355 extern void usysdep_get_work_free P((const struct uuconf_system *qsys));
356 \f
357 /* Add a base name to a file if it is a directory.  If zfile names a
358    directory, then return a string naming a file within the directory
359    with the base file name of zname.  This should return NULL on
360    error.  */
361 extern char *zsysdep_add_base P((const char *zfile,
362                                  const char *zname));
363
364 /* Get a file name from the spool directory.  This should return NULL
365    on error.  The pseq argument is TRUE if the file was found from
366    searching the work directory; this is, unfortunately, needed to
367    support SVR4 spool directories.  */
368 extern char *zsysdep_spool_file_name P((const struct uuconf_system *qsys,
369                                         const char *zfile,
370                                         pointer pseq));
371
372 /* Make necessary directories.  This should create all non-existent
373    directories for a file.  If the fpublic argument is TRUE, anybody
374    should be permitted to create and remove files in the directory;
375    otherwise anybody can list the directory, but only the UUCP system
376    can create and remove files.  It should return FALSE on error.  */
377 extern boolean fsysdep_make_dirs P((const char *zfile, boolean fpublic));
378
379 /* Create a stdio file, setting appropriate protection.  If the
380    fpublic argument is TRUE, the file is made publically accessible;
381    otherwise it is treated as a private data file.  If the fappend
382    argument is TRUE, the file is opened in append mode; otherwise any
383    previously existing file of the same name is removed.  If the
384    fmkdirs argument is TRUE, then any necessary directories should
385    also be created.  On a system in which file protections are
386    unimportant and the necessary directories exist, this may be
387    implemented as
388
389    fopen (zfile, fappend ? "a" : "w");
390
391    */
392 extern FILE *esysdep_fopen P((const char *zfile, boolean fpublic,
393                               boolean fappend, boolean fmkdirs));
394
395 /* Open a file, using the access permission of the user who invoked
396    the program.  The frd argument is TRUE if the file should be opened
397    for reading, and the fbinary argument is TRUE if the file should be
398    opened as a binary file (this is ignored on Unix, since there all
399    files are binary files).  This returns an openfile_t, not a FILE *.
400    This is supposed to be able to open a file even if it can not be
401    read by the uucp user.  This is not possible on some older Unix
402    systems.  */
403 extern openfile_t esysdep_user_fopen P((const char *zfile,
404                                         boolean frd, boolean fbinary));
405
406 /* Open a file to send to another system; the qsys argument is the
407    system the file is being sent to.  If fcheck is TRUE, it should
408    make sure that the file is readable by zuser (if zuser is NULL the
409    file must be readable by anybody).  This is to eliminate a window
410    between fsysdep_in_directory and esysdep_open_send.  If an error
411    occurs, it should return EFILECLOSED.  */
412 extern openfile_t esysdep_open_send P((const struct uuconf_system *qsys,
413                                        const char *zname,
414                                        boolean fcheck,
415                                        const char *zuser));
416
417 /* Return a temporary file name to receive into.  This file will be
418    opened by esysdep_open_receive.  The qsys argument is the system
419    the file is coming from, the zto argument is the name the file will
420    have after it has been fully received, the ztemp argument, if it is
421    not NULL, is from the command sent by the remote system, and the
422    frestart argument is TRUE if the protocol and remote system permit
423    file transfers to be restarted.  The return value must be freed
424    using ubuffree.  The function should return NULL on error.  */
425 extern char *zsysdep_receive_temp P((const struct uuconf_system *qsys,
426                                      const char *zfile,
427                                      const char *ztemp,
428                                      boolean frestart));
429
430 /* Open a file to receive from another system.  The zreceive argument
431    is the return value of zsysdep_receive_temp with the same qsys,
432    zfile and ztemp arguments.  If the function can determine that this
433    file has already been partially received, it should set *pcrestart
434    to the number of bytes that have been received.  If the file has
435    not been partially received, *pcrestart should be set to -1.
436    pcrestart will be passed in as NULL if file restart is not
437    supported by the protocol or the remote system.  The function
438    should return EFILECLOSED on error.  After the file is written,
439    fsysdep_move_file will be called to move the file to its final
440    destination, and to set the correct file mode.  */
441 extern openfile_t esysdep_open_receive P((const struct uuconf_system *qsys,
442                                           const char *zto,
443                                           const char *ztemp,
444                                           const char *zreceive,
445                                           long *pcrestart));
446
447 /* Move a file.  This is used to move a received file to its final
448    location.  The zto argument is the file to create.  The zorig
449    argument is the name of the file to move.  If fmkdirs is TRUE, then
450    any necessary directories are created; fpublic indicates whether
451    they should be publically writeable or not.  If fcheck is TRUE,
452    this should make sure the directory is writeable by the user zuser
453    (if zuser is NULL, then it must be writeable by any user); this is
454    to avoid a window of vulnerability between fsysdep_in_directory and
455    fsysdep_move_file.  This function should return FALSE on error, in
456    which case the zorig file should still exist.  */
457 extern boolean fsysdep_move_file P((const char *zorig, const char *zto,
458                                     boolean fmkdirs, boolean fpublic,
459                                     boolean fcheck, const char *zuser));
460
461 /* Change the mode of a file.  The imode argument is a Unix mode.
462    This should return FALSE on error.  */
463 extern boolean fsysdep_change_mode P((const char *zfile,
464                                       unsigned int imode));
465
466 /* Truncate a file which we are receiving into.  This may be done by
467    closing the original file, removing it and reopening it.  This
468    should return FALSE on error.  */
469 extern openfile_t esysdep_truncate P((openfile_t e, const char *zname));
470
471 /* Sync a file to disk.  If this fails it should log an error using
472    the zmsg parameter, and return FALSE.  This is controlled by the
473    FSYNC_ON_CLOSE macro in policy.h.  */
474 extern boolean fsysdep_sync P((openfile_t e, const char *zmsg));
475 \f
476 /* It is possible for the acknowledgement of a received file to be
477    lost.  The sending system will then now know that the file was
478    correctly received, and will send it again.  This can be a problem
479    particularly with protocols which support channels, since they may
480    send several small files in a single window, all of which may be
481    received correctly although the sending system never sees the
482    acknowledgement.  If these files involve an execution, the
483    execution will happen twice, which will be bad.
484
485    This function is called when a file is completely received.  It is
486    supposed to try and remember the reception, in case the connection
487    is lost.  It is passed the system, the file name to receive to, and
488    the temporary file name from the sending system.  It should return
489    FALSE on error.  */
490 extern boolean fsysdep_remember_reception P((const struct uuconf_system *qsys,
491                                              const char *zto,
492                                              const char *ztemp));
493
494 /* This function is called to see if a file has already been received
495    successfully.  It gets the same arguments as
496    fsysdep_remember_reception.  It should return TRUE if the file was
497    already received, FALSE otherwise.  There is no way to report
498    error.  */
499 extern boolean fsysdep_already_received P((const struct uuconf_system *qsys,
500                                            const char *zto,
501                                            const char *ztemp));
502
503 /* This function is called when it is no longer necessary to remember
504    that a file has been received.  This will be called when the
505    protocol knows that the receive message has been acknowledged.  It
506    gets the same arguments as fsysdep_remember_reception.  it should
507    return FALSE on error.  */
508 extern boolean fsysdep_forget_reception P((const struct uuconf_system *qsys,
509                                            const char *zto,
510                                            const char *ztemp));
511 \f
512 /* Start expanding a wildcarded file name.  This should return FALSE
513    on error; otherwise subsequent calls to zsysdep_wildcard should
514    return file names.  */
515 extern boolean fsysdep_wildcard_start P((const char *zfile));
516
517 /* Get the next wildcard name.  This should return NULL when there are
518    no more names to return.  The return value should be freed using
519    ubuffree.  The argument should be the same as that to
520    fsysdep_wildcard_start.  There is no way to return error.  */
521 extern char *zsysdep_wildcard P((const char *zfile));
522
523 /* Finish getting wildcard names.  This may be called before or after
524    zsysdep_wildcard has returned NULL.  It should return FALSE on
525    error.  */
526 extern boolean fsysdep_wildcard_end P((void));
527 \f
528 /* Prepare to execute a bunch of file transfer requests.  This should
529    make an entry in the spool directory so that the next time uucico
530    is started up it will transfer these files.  The bgrade argument
531    specifies the grade of the commands.  The commands themselves are
532    in the pascmds array, which has ccmds entries.  The function should
533    return NULL on error, or the jobid on success.  The jobid is a
534    string that may be printed or passed to fsysdep_kill_job and
535    related functions, but is otherwise uninterpreted.  */
536 extern char *zsysdep_spool_commands P((const struct uuconf_system *qsys,
537                                        int bgrade, int ccmds,
538                                        const struct scmd *pascmds));
539
540 /* Get a file name to use for a data file to be copied to another
541    system.  The ztname, zdname and zxname arguments will all either be
542    NULL or point to an array of CFILE_NAME_LEN characters in length.
543    The ztname array should be set to a temporary file name that could
544    be passed to zsysdep_spool_file_name to retrieve the return value
545    of this function; this will be appropriate for the temporary name
546    in a send request.  The zdname array should be set to a data file
547    name that is appropriate for the spool directory of the other
548    system; this will be appropriate for the name of the destination
549    file in a send request of a data file for an execution of some
550    sort.  The zxname array should be set to an execute file name that
551    is appropriate for the other system.  The zlocalname argument is
552    the name of the local system as seen by the remote system, the
553    bgrade argument is the grade, and fxqt is TRUE if this file is
554    going to become an execution file.  This should return NULL on
555    error.  */
556 #define CFILE_NAME_LEN (15)
557
558 extern char *zsysdep_data_file_name P((const struct uuconf_system *qsys,
559                                        const char *zlocalname,
560                                        int bgrade, boolean fxqt,
561                                        char *ztname, char *zdname,
562                                        char *zxname));
563
564 /* Get a name for a local execute file.  This is used by uux for a
565    local command with remote files.  Returns NULL on error.  */
566 extern char *zsysdep_xqt_file_name P((void));
567 \f
568 /* Beginning getting execute files.  To get a list of execute files,
569    first fsysdep_get_xqt_init is called, then zsysdep_get_xqt is
570    called several times until it returns NULL, then finally
571    usysdep_get_xqt_free is called.  If the zsystem argument is not
572    NULL, it is the name of a system for which execution files are
573    desired.  */
574 extern boolean fsysdep_get_xqt_init P((const char *zsystem));
575
576 /* Get the next execute file.  This should return NULL when finished
577    (with *pferr set to FALSE).  The zsystem argument should be the
578    same string as that passed to fsysdep_get_xqt_init.  On an error
579    this should return NULL with *pferr set to TRUE.  This should set
580    *pzsystem to the name of the system for which the execute file was
581    created; this is not guaranteed to match the zsystem argument--that
582    must be double checked by the caller.  Both the return value and
583    *pzsystem should be freed using ubuffree.  */
584 extern char *zsysdep_get_xqt P((const char *zsystem, char **pzsystem,
585                                 boolean *pferr));
586
587 /* Clean up after getting execute files.  The zsystem argument should
588    be the same string as that passed to fsysdep_get_xqt_init.  */
589 extern void usysdep_get_xqt_free P((const char *zsystem));
590 \f
591 /* Get the absolute pathname of a command to execute.  This is given
592    the legal list of commands (which may be the special case "ALL")
593    and the path.  It must return an absolute pathname to the command.
594    If it gets an error it should set *pferr to TRUE and return NULL;
595    if the command is not found it should set *pferr to FALSE and
596    return NULL.  */
597 extern char *zsysdep_find_command P((const char *zcmd, char **pzcmds,
598                                      char **pzpath, boolean *pferr));
599
600 /* Expand file names for uuxqt.  This exists because uuxqt on Unix has
601    to expand file names which begin with a ~.  It does not want to
602    expand any other type of file name, and it turns a double ~ into a
603    single one without expanding.  If this returns NULL, the file does
604    not need to be changed; otherwise it returns a zbufalc'ed string.
605    There is no way to report error.  */
606 extern char *zsysdep_xqt_local_file P((const struct uuconf_system *qsys,
607                                        const char *zfile));
608
609 #if ! ALLOW_FILENAME_ARGUMENTS
610 /* Check an argument to an execution command to make sure that it
611    doesn't refer to a file name that may not be accessed.  This should
612    check the argument to see if it is a filename.  If it is, it should
613    either reject it out of hand or it should call fin_directory_list
614    on the file with both qsys->zremote_receive and qsys->zremote_send.
615    If the file is rejected, it should log an error and return FALSE.
616    Otherwise it should return TRUE.  */
617 extern boolean fsysdep_xqt_check_file P((const struct uuconf_system *qsys,
618                                          const char *zfile));
619 #endif /* ! ALLOW_FILENAME_ARGUMENTS */
620
621 /* Run an execute file.  The arguments are:
622
623    qsys -- system for which execute file was created
624    zuser -- user who requested execution
625    pazargs -- list of arguments to command (element 0 is command)
626    zfullcmd -- command and arguments stuck together in one string
627    zinput -- file name for standard input (may be NULL)
628    zoutput -- file name for standard output (may be NULL)
629    fshell -- if TRUE, use /bin/sh to execute file
630    ilock -- return value of ixsysdep_lock_uuxqt
631    pzerror -- set to name of standard error file
632    pftemp -- set to TRUE if error is temporary, FALSE otherwise
633
634    If fshell is TRUE, the command should be executed with /bin/sh
635    (obviously, this can only really be done on Unix systems).  If an
636    error occurs this should return FALSE and set *pftemp
637    appropriately.  *pzerror should be freed using ubuffree.  */
638 extern boolean fsysdep_execute P((const struct uuconf_system *qsys,
639                                   const char *zuser,
640                                   const char **pazargs,
641                                   const char *zfullcmd,
642                                   const char *zinput,
643                                   const char *zoutput,
644                                   boolean fshell,
645                                   int ilock,
646                                   char **pzerror,
647                                   boolean *pftemp));
648
649 /* Lock for uuxqt execution.  If the cmaxuuxqts argument is not zero,
650    this should make sure that no more than cmaxuuxqts uuxqt processes
651    are running at once.  Also, only one uuxqt may execute a particular
652    command (specified by the -c option) at a time.  If zcmd is not
653    NULL, it is a command that must be locked.  This should return a
654    nonnegative number which will be passed to other routines,
655    including fsysdep_unlock_uuxqt, or -1 on error.  */
656 extern int ixsysdep_lock_uuxqt P((const char *zcmd,
657                                   int cmaxuuxqts));
658
659 /* Unlock a uuxqt process.  This is passed the return value of
660    ixsysdep_lock_uuxqt, as well as the arguments passed to
661    ixsysdep_lock_uuxqt.  It may return FALSE on error, but at present
662    the return value is ignored.  */
663 extern boolean fsysdep_unlock_uuxqt P((int iseq, const char *zcmd,
664                                        int cmaxuuxqts));
665
666 /* See whether a particular uuxqt command is locked.  This should
667    return TRUE if the command is locked (because ixsysdep_lock_uuxqt
668    was called with it as an argument), FALSE otherwise.  There is no
669    way to return error.  */
670 extern boolean fsysdep_uuxqt_locked P((const char *zcmd));
671
672 /* Lock an execute file in order to execute it.  This should return
673    FALSE if the execute file is already locked.  There is no way to
674    return error.  */
675 extern boolean fsysdep_lock_uuxqt_file P((const char *zfile));
676
677 /* Unlock an execute file.  This should return FALSE on error.  */
678 extern boolean fsysdep_unlock_uuxqt_file P((const char *zfile));
679
680 /* Lock the execution directory.  The ilock argument is the return
681    value of ixsysdep_lock_uuxqt.  This should return FALSE if the
682    directory is already locked.  There is no way to return error.  */
683 extern boolean fsysdep_lock_uuxqt_dir P((int ilock));
684
685 /* Remove all files in the execution directory, and unlock it.  This
686    should return FALSE on error.  */
687 extern boolean fsysdep_unlock_uuxqt_dir P((int ilock));
688
689 /* Move files into or out of the execution directory.  The code will
690    already have checked that all the files exist.  The elements in the
691    pzfrom array will be complete filenames, and the elements in the
692    pzto array will be either NULL (in which case the file should not
693    be moved) or simple base names.  If fto is TRUE, the files in
694    pzfrom should be moved to pzto; otherwise, the files in pzto should
695    be moved to pzfrom (this is used if a temporary failure occurs, in
696    which case the execution will be retried later).  If pzinput and
697    *pzinput are not NULL, then it is the name of the standard input
698    file; if it is the same as any element of pzfrom, then *pzinput
699    should be set to the zbufcpy of the corresponding pzto value, if
700    any.  */
701 extern boolean fsysdep_move_uuxqt_files P((int cfiles,
702                                            const char *const *pzfrom,
703                                            const char *const *pzto,
704                                            boolean fto, int ilock,
705                                            char **pzinput));
706 \f
707 /* Expand a file name on the local system, defaulting to the current
708    directory.  This is just like zsysdep_local_file, except that
709    relative files are placed in the working directory the program
710    started in rather than in the public directory.  This should return
711    NULL on error.  */
712 extern char *zsysdep_local_file_cwd P((const char *zname,
713                                        const char *zpubdir,
714                                        boolean *pfbadname));
715
716 /* Add the working directory to a file name.  The named file is
717    actually on a remote system.  If the file already has a directory,
718    it should not be changed.  This should return NULL on error.  */
719 extern char *zsysdep_add_cwd P((const char *zfile));
720
721 /* See whether a file name will need the current working directory
722    when zsysdep_local_file_cwd or zsysdep_add_cwd is called on it.
723    This will be called before usysdep_initialize.  It should just
724    check whether the argument is an absolute path.  See the comment
725    above usysdep_initialize in this file for an explanation of why
726    things are done this way.  */
727 extern boolean fsysdep_needs_cwd P((const char *zfile));
728
729 /* Get the base name of a file.  The file will be a local file name,
730    and this function should return the base file name, ideally in a
731    form which will make sense on most systems; it will be used if the
732    destination of a uucp is a directory.  */
733 extern char *zsysdep_base_name P((const char *zfile));
734
735 /* Return a filename within a directory.  */
736 extern char *zsysdep_in_dir P((const char *zdir, const char *zfile));
737
738 /* Get the mode of a file.  This should return a Unix style file mode.
739    It should return 0 on error.  */
740 extern unsigned int ixsysdep_file_mode P((const char *zfile));
741
742 /* See whether the user has access to a file.  This is called by uucp
743    and uux to prevent copying of a file which uucp can read but the
744    user cannot.  If access is denied, this should log an error message
745    and return FALSE.  */
746 extern boolean fsysdep_access P((const char *zfile));
747
748 /* See whether the daemon has access to a file.  This is called by
749    uucp and uux when a file is queued up for transfer without being
750    copied into the spool directory.  It is merely an early error
751    check, as the daemon would of course discover the error itself when
752    it tried the transfer.  If access would be denied, this should log
753    an error message and return FALSE.  */
754 extern boolean fsysdep_daemon_access P((const char *zfile));
755
756 /* Translate a destination from system!user to a place in the public
757    directory where uupick will get the file.  On Unix this produces
758    system!~/receive/user/localname, and that's probably what it has to
759    produce on any other system as well.  Returns NULL on a usage
760    error, or otherwise returns string allocated by zbufcpy.  */
761 extern char *zsysdep_uuto P((const char *zdest,
762                              const char *zlocalname));
763
764 /* Return TRUE if a pathname exists and is a directory.  */
765 extern boolean fsysdep_directory P((const char *zpath));
766
767 /* Walk a directory tree.  The zdir argument is the directory to walk.
768    The pufn argument is a function to call on each regular file in the
769    tree.  The first argument to pufn should be the full filename; the
770    second argument to pufn should be the filename relative to zdir;
771    the third argument to pufn should be the pinfo argument to
772    usysdep_walk_tree.  The usysdep_walk_tree function should return
773    FALSE on error.  */
774 extern boolean usysdep_walk_tree P((const char *zdir,
775                                     void (*pufn) P((const char *zfull,
776                                                     const char *zrelative,
777                                                     pointer pinfo)),
778                                     pointer pinfo));
779 \f
780 /* Return the jobid of a work file, given the sequence value.  On
781    error this should log an error and return NULL.  The jobid is a
782    string which may be printed out and read in and passed to
783    fsysdep_kill_job, etc., but is not otherwise interpreted.  */
784 extern char *zsysdep_jobid P((const struct uuconf_system *qsys,
785                               pointer pseq));
786
787 /* See whether the current user is privileged.  Privileged users are
788    permitted to kill jobs submitted by another user, and they are
789    permitted to use the -u argument to uucico; other uses of this call
790    may be added later.  This should return TRUE if permission is
791    granted, FALSE otherwise.  */
792 extern boolean fsysdep_privileged P((void));
793
794 /* Kill a job, given the jobid.  This should remove all associated
795    files and in general eliminate the job completely.  On error it
796    should log an error message and return FALSE.  */
797 extern boolean fsysdep_kill_job P((pointer puuconf,
798                                    const char *zjobid));
799
800 /* Rejuvenate a job, given the jobid.  If possible, this should update
801    the time associated with the job such that it will not be
802    eliminated by uustat -K or similar programs that check the creation
803    time.  This should affect the return value of ixsysdep_work_time.
804    On error it should log an error message and return FALSE.  */
805 extern boolean fsysdep_rejuvenate_job P((pointer puuconf,
806                                          const char *zjobid));
807
808 /* Get the time a job was queued, given the sequence number.  There is
809    no way to indicate error.  The return value must use the same epoch
810    as ixsysdep_time.  */
811 extern long ixsysdep_work_time P((const struct uuconf_system *qsys,
812                                   pointer pseq));
813
814 /* Get the time a file was created.  This is called by uustat on
815    execution files.  There is no way to indicate error.  The return
816    value must use the same epoch as ixsysdep_time.  */
817 extern long ixsysdep_file_time P((const char *zfile));
818
819 /* Touch a file to make it appear as though it was created at the
820    current time.  This is called by uustat on execution files.  On
821    error this should log an error message and return FALSE.  */
822 extern boolean fsysdep_touch_file P((const char *zfile));
823
824 /* Get the size in bytes of a file.  If this file does not exist, this
825    should not give an error message, but should return -1.  If some
826    other error occurs, this should return -2.  */
827 extern long csysdep_size P((const char *zfile));
828
829 /* Return the amount of free space on the containing the given file
830    name (the file may or may not exist).  If the amount of free space
831    cannot be determined, the function should return -1.  */
832 extern long csysdep_bytes_free P((const char *zfile));
833
834 /* Start getting status information for all systems with available
835    status information.  There may be status information for unknown
836    systems, which is why this series of functions is used.  The phold
837    argument is used to pass information around, to possibly avoid the
838    use of static variables.  On error this should log an error and
839    return FALSE.  */
840 extern boolean fsysdep_all_status_init P((pointer *phold));
841
842 /* Get status information for the next system.  This should return the
843    system name and fill in the qstat argument.  The phold argument
844    will be that set by fsysdep_all_status_init.  On error this should
845    log an error, set *pferr to TRUE, and return NULL.  */
846 extern char *zsysdep_all_status P((pointer phold, boolean *pferr,
847                                    struct sstatus *qstat));
848
849 /* Free up anything allocated by fsysdep_all_status_init and
850    zsysdep_all_status.  The phold argument is that set by
851    fsysdep_all_status_init.  */
852 extern void usysdep_all_status_free P((pointer phold));
853
854 /* Display the process status of all processes holding lock files.
855    This is uustat -p.  The return value is passed to usysdep_exit.  */
856 extern boolean fsysdep_lock_status P((void));
857 \f
858 /* Return TRUE if the user has legitimate access to the port.  This is
859    used by cu to control whether the user can open a port directly,
860    rather than merely being able to dial out on it.  Opening a port
861    directly allows the modem to be reprogrammed.  */
862 extern boolean fsysdep_port_access P((struct uuconf_port *qport));
863
864 /* Return whether the given port could be named by the given line.  On
865    Unix, the line argument would be something like "ttyd0", and this
866    function should return TRUE if the named port is "/dev/ttyd0".  */
867 extern boolean fsysdep_port_is_line P((struct uuconf_port *qport,
868                                        const char *zline));
869
870 /* Set the terminal into raw mode.  In this mode no input characters
871    should be treated specially, and characters should be made
872    available as they are typed.  The original terminal mode should be
873    saved, so that it can be restored by fsysdep_terminal_restore.  If
874    flocalecho is TRUE, then local echoing should still be done;
875    otherwise echoing should be disabled.  This function returns FALSE
876    on error.  */
877 extern boolean fsysdep_terminal_raw P((boolean flocalecho));
878
879 /* Restore the terminal back to the original setting, before
880    fsysdep_terminal_raw was called.  Returns FALSE on error.  */
881 extern boolean fsysdep_terminal_restore P((void));
882
883 /* Read a line from the terminal.  The fsysdep_terminal_raw function
884    will have been called.  This should print the zprompt argument
885    (unless it is NULL) and return the line, allocated by zbufcpy, or
886    NULL on error.  */
887 extern char *zsysdep_terminal_line P((const char *zprompt));
888
889 /* Write a line to the terminal, ending with a newline.  This is
890    basically just puts (zline, stdout), except that the terminal will
891    be in raw mode, so on ASCII Unix systems the line needs to end with
892    \r\n.  */
893 extern boolean fsysdep_terminal_puts P((const char *zline));
894
895 /* If faccept is TRUE, permit the user to generate signals from the
896    terminal.  If faccept is FALSE, turn signals off again.  After
897    fsysdep_terminal_raw is called, signals should be off.  Return
898    FALSE on error.  */
899 extern boolean fsysdep_terminal_signals P((boolean faccept));
900
901 /* The cu program expects the system dependent code to handle the
902    details of copying data from the communications port to the
903    terminal.  This should be set up by fsysdep_cu_init, and done while
904    fsysdep_cu is called.  It is permissible to do it on a continual
905    basis (on Unix a subprocess handles it) so long as the copying can
906    be stopped by the fsysdep_cu_copy function.
907
908    The fsysdep_cu_init function does any system dependent
909    initialization needed for this.  */
910 extern boolean fsysdep_cu_init P((struct sconnection *qconn));
911
912 /* Copy all data from the communications port to the terminal, and all
913    data from the terminal to the communications port.  Keep this up
914    until the escape character *zCuvar_escape is seen.  Set *pbcmd to
915    the character following the escape character; after the escape
916    character, zlocalname should be printed, possibly after a delay.
917    If two escape characters are entered in sequence, this function
918    should send a single escape character to the port, and not return.
919    Returns FALSE on error.  */
920 extern boolean fsysdep_cu P((struct sconnection *qconn,
921                              char *pbcmd,
922                              const char *zlocalname));
923
924 /* If fcopy is TRUE, start copying data from the communications port
925    to the terminal.  If fcopy is FALSE, stop copying data.  This
926    function may be called several times during a cu session.  It
927    should return FALSE on error.  */
928 extern boolean fsysdep_cu_copy P((boolean fcopy));
929
930 /* Stop copying data from the communications port to the terminal, and
931    generally clean up after fsysdep_cu_init and fsysdep_cu.  Returns
932    FALSE on error.  */
933 extern boolean fsysdep_cu_finish P((void));
934
935 /* Run a shell command.  If zcmd is NULL, or *zcmd == '\0', just
936    start up a shell.  The second argument is one of the following
937    values.  This should return FALSE on error.  */
938 enum tshell_cmd
939 {
940   /* Attach stdin and stdout to the terminal.  */
941   SHELL_NORMAL,
942   /* Attach stdout to the communications port, stdin to the terminal.  */
943   SHELL_STDOUT_TO_PORT,
944   /* Attach stdin to the communications port, stdout to the terminal.  */
945   SHELL_STDIN_FROM_PORT,
946   /* Attach both stdin and stdout to the communications port.  */
947   SHELL_STDIO_ON_PORT
948 };
949
950 extern boolean fsysdep_shell P((struct sconnection *qconn,
951                                 const char *zcmd,
952                                 enum tshell_cmd tcmd));
953
954 /* Change directory.  If zdir is NULL, or *zdir == '\0', change to the
955    user's home directory.  Return FALSE on error.  */
956 extern boolean fsysdep_chdir P((const char *zdir));
957
958 /* Suspend the current process.  This is only expected to work on Unix
959    versions that support SIGTSTP.  In general, people can just shell
960    out.  */
961 extern boolean fsysdep_suspend P((void));
962 \f
963 /* Start getting files for uupick.  The zsystem argument may be NULL
964    to get files from all systems, or it may specify a particular
965    system.  The zpubdir argument is the public directory to use.  This
966    returns FALSE on error.  */
967 extern boolean fsysdep_uupick_init P((const char *zsystem,
968                                       const char *zpubdir));
969
970 /* Get the next file for uupick.  This returns the basic file name.
971    It sets *pzfull to the full name, and *pzfrom to the name of the
972    system which sent this file over; both should be freed using
973    ubuffree.  *pzfull should be passed to ubuffree after it is no
974    longer needed.  The zsystem and zpubdir arguments should be the
975    same as the arguments to fsysdep_uupick_init.  This returns NULL
976    when all files been returned.  */
977 extern char *zsysdep_uupick P((const char *zsystem, const char *zpubdir,
978                                char **pzfrom, char **pzfull));
979
980 /* Clean up after getting files for uupick.  */
981 extern boolean fsysdep_uupick_free P((const char *zsystem,
982                                       const char *zpubdir));
983
984 /* Translate a local file name for uupick.  On Unix this is just like
985    zsysdep_local_file_cwd except that a file beginning with ~/ is
986    placed in the user's home directory rather than in the public
987    directory.  */
988 extern char *zsysdep_uupick_local_file P((const char *zfile,
989                                           boolean *pfbadname));
990
991 /* Remove a directory and all the files in it.  */
992 extern boolean fsysdep_rmdir P((const char *zdir));
993
994 #endif /* ! defined (SYSTEM_H) */