1772
|
1 /* getdirs.c Routine to get pathname for specified directory.
|
|
2 Copyright (C) 1993 Bob Billson
|
|
3
|
|
4 This file is part of the OS-9 UUCP package, UUCPbb.
|
|
5
|
|
6 This program is free software; you can redistribute it and/or modify
|
|
7 it under the terms of the GNU General Public License as published by
|
|
8 the Free Software Foundation; either version 2 of the License, or
|
|
9 (at your option) any later version.
|
|
10
|
|
11 This program is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with this program; if not, write to the Free Software
|
|
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
19
|
|
20 The author of UUCPbb, Bob Billson, can be contacted at:
|
|
21 bob@kc2wz.bubble.org or uunet!kc2wz!bob or by snail mail:
|
|
22 21 Bates Way, Westfield, NJ 07090
|
|
23 */
|
|
24
|
|
25 /* Function to get directory name from the /dd/sys/uucp/Parameters file. A
|
|
26 pointer to a malloc()'ed string containing the name is returned. It is the
|
|
27 responsibility of the calling function to free() the memory when it is no
|
|
28 longer needed. If the Parameters file can't be read or no matching
|
|
29 directory is found, a NULL is returned. */
|
|
30
|
|
31 #include "uucp.h"
|
|
32
|
|
33 #define WORDSIZE 3
|
|
34
|
|
35 EXTERN char fname[];
|
|
36 EXTERN QQ unsigned myuid;
|
|
37
|
|
38
|
|
39 char *getdirs (directory)
|
|
40 char *directory;
|
|
41 {
|
|
42 char line[100];
|
|
43 register char *p;
|
|
44 FILE *fp;
|
|
45 char *p2, *words[WORDSIZE];
|
|
46 int n, linecount, dirlen = strlen (directory);
|
|
47
|
|
48 p = line;
|
|
49 sprintf (fname, "%s/Parameters", UUCPSYS);
|
|
50 asetuid (0);
|
|
51
|
|
52 if ((fp = fopen (fname, "r")) == NULL)
|
|
53 {
|
|
54 sprintf (p, "getdirs: can't open %s", fname);
|
|
55 asetuid (myuid);
|
|
56 return (p2);
|
|
57 }
|
|
58
|
|
59 asetuid (myuid);
|
|
60 p2 = (char *)NULL;
|
|
61 linecount = 0;
|
|
62 while (mfgets (p, sizeof (line), fp) != NULL)
|
|
63 {
|
|
64 ++linecount;
|
|
65
|
|
66 if (strnucmp (directory, p, dirlen) == 0)
|
|
67 {
|
|
68 n = getargs (words, p, WORDSIZE);
|
|
69
|
|
70 if (n != 3 || words[1][0] != '=')
|
|
71 {
|
|
72 fprintf (stderr,
|
|
73 "getdirs: bad line in Parameters at line %d\n",
|
|
74 linecount);
|
|
75 }
|
|
76 else
|
|
77 p2 = strdup (words[2]);
|
|
78 break;
|
|
79 }
|
|
80 }
|
|
81 fclose (fp);
|
|
82 return (p2);
|
|
83 }
|