|
|
1.1 root 1: /* seq.c
2: Get and increment the conversation sequence number for a system.
3:
4: Copyright (C) 1991, 1992 Ian Lance Taylor
5:
6: This file is part of the Taylor UUCP package.
7:
8: This program is free software; you can redistribute it and/or
9: modify it under the terms of the GNU General Public License as
10: published by the Free Software Foundation; either version 2 of the
11: License, or (at your option) any later version.
12:
13: This program is distributed in the hope that it will be useful, but
14: WITHOUT ANY WARRANTY; without even the implied warranty of
15: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16: General Public License for more details.
17:
18: You should have received a copy of the GNU General Public License
19: along with this program; if not, write to the Free Software
20: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21:
22: The author of the program may be contacted at [email protected] or
23: c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
24: */
25:
26: #include "uucp.h"
27:
28: #include "uudefs.h"
29: #include "uuconf.h"
30: #include "sysdep.h"
31: #include "system.h"
32:
33: #include <errno.h>
34:
35: /* Get the current conversation sequence number for a remote system,
36: and increment it for next time. The conversation sequence number
37: is kept in a file named for the system in the directory .Sequence
38: in the spool directory. This is not compatible with other versions
39: of UUCP, but it makes more sense to me. The sequence file is only
40: used if specified in the information for that system. */
41:
42: long
43: ixsysdep_get_sequence (qsys)
44: const struct uuconf_system *qsys;
45: {
46: FILE *e;
47: char *zname;
48: struct stat s;
49: long iseq;
50:
51: /* This will only be called when the system is locked anyhow, so there
52: is no need to use a separate lock for the conversation sequence
53: file. */
54: zname = zsysdep_in_dir (".Sequence", qsys->uuconf_zname);
55:
56: iseq = 0;
57: if (stat (zname, &s) == 0)
58: {
59: boolean fok;
60: char *zline;
61: size_t cline;
62:
63: /* The file should only be readable and writable by uucp. */
64: if ((s.st_mode & (S_IRWXG | S_IRWXO)) != 0)
65: {
66: ulog (LOG_ERROR,
67: "Bad file protection for conversation sequence file");
68: ubuffree (zname);
69: return -1;
70: }
71:
72: e = fopen (zname, "r+");
73: if (e == NULL)
74: {
75: ulog (LOG_ERROR, "fopen (%s): %s", zname, strerror (errno));
76: ubuffree (zname);
77: return -1;
78: }
79:
80: ubuffree (zname);
81:
82: fok = TRUE;
83: zline = NULL;
84: cline = 0;
85: if (getline (&zline, &cline, e) <= 0)
86: fok = FALSE;
87: else
88: {
89: char *zend;
90:
91: iseq = strtol (zline, &zend, 10);
92: if (zend == zline)
93: fok = FALSE;
94: }
95:
96: xfree ((pointer) zline);
97:
98: if (! fok)
99: {
100: ulog (LOG_ERROR, "Bad format for conversation sequence file");
101: (void) fclose (e);
102: return -1;
103: }
104:
105: rewind (e);
106: }
107: else
108: {
109: e = esysdep_fopen (zname, FALSE, FALSE, TRUE);
110: ubuffree (zname);
111: if (e == NULL)
112: return -1;
113: }
114:
115: ++iseq;
116:
117: fprintf (e, "%ld", iseq);
118:
119: if (fclose (e) != 0)
120: {
121: ulog (LOG_ERROR, "fclose: %s", strerror (errno));
122: return -1;
123: }
124:
125: return iseq;
126: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.