xref: /titanic_50/usr/src/cmd/bnu/bnuconvert.c (revision f38cb554a534c6df738be3f4d23327e69888e634)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include	"uucp.h"
34 
35 int
36 main(argc, argv)
37 int argc;
38 char **argv;
39 {
40 	char fdgrade();
41 	DIR *machdir, *spooldir;
42 	char machname[MAXFULLNAME];
43 	char file1[NAMESIZE+1], file2[NAMESIZE+1];
44 	struct cs_struct svdcfile;
45 	int c;
46 
47 	(void) strcpy(Progname, "bnuconvert");
48 
49 	Uid = getuid();
50 	Euid = geteuid();
51 	if (Uid == 0)
52 		(void) setuid(UUCPUID);
53 
54 	while ((c = getopt(argc, argv, "x:")) != EOF)
55 		switch(c) {
56 		case 'x':
57 			Debug = atoi(optarg);
58 			if (Debug < 0)
59 				Debug = 1;
60 			break;
61 		default:
62 			(void) fprintf(stderr, "usage: bnuconvert [-xLEVEL]\n");
63 			exit(-1);
64 		}
65 
66 	DEBUG(5, "Progname (%s): STARTED\n", Progname);
67 
68 	/* find the default directory to queue to */
69 
70 	if (eaccess(GRADES, 04) != -1)
71 		svdcfile.grade = fdgrade();
72 	else
73 		svdcfile.grade = D_QUEUE;
74 
75 	DEBUG(5, "All jobs will be placed in directory (%c) ", svdcfile.grade);
76 	DEBUG(5, "under each remote name in the spool area.%c\n", NULLCHAR);
77 
78 	if ((spooldir = opendir(SPOOL)) == NULL) {
79 		(void) fprintf(stderr, "CAN'T OPEN (%s): errno (%d)\n",
80 			SPOOL, errno);
81 		exit(1);
82 	}
83 
84 	while (gdirf(spooldir, file1, SPOOL)) {
85 
86 		(void) sprintf(Rmtname, "%s", file1);
87 		(void) sprintf(machname, "%s/%s", SPOOL, file1);
88 		DEBUG(9, "File1 is (%s)\n", file1);
89 		DEBUG(9, "Rmtname is (%s)\n", Rmtname);
90 		DEBUG(9, "Machname is (%s)\n", machname);
91 
92 		if (chdir(machname) != 0) {
93 			(void) fprintf(stderr, "CAN'T CHDIR (%s): errno (%d)\n",
94 				machname, errno);
95 			exit(1);
96 		}
97 
98 		if ((machdir = opendir(machname)) == NULL) {
99 			(void) fprintf(stderr, "CAN'T OPEN (%s): errno (%d)\n",
100 				machname, errno);
101 				continue;
102 		}
103 
104 		DEBUG(7, "Directory: %s\n", machname);
105 
106 		while (gnamef(machdir, file2) == TRUE) {
107 
108 			DEBUG(9, "File read from (%s) ", machname);
109 			DEBUG(9, "is (%s)\n", file2);
110 
111 			if (!EQUALSN(file2, "C.",2))
112 				continue;
113 
114 			/* build a saved C. file structure */
115 
116 			(void) strncpy(svdcfile.file, file2, NAMESIZE-1);
117 			(void) sprintf(svdcfile.sys, "%s/%c", Rmtname, svdcfile.grade);
118 
119 			DEBUG(9, "Rmtname is (%s)\n", Rmtname);
120 			DEBUG(9, "Default directory to queue to is (%c)\n", svdcfile.grade);
121 			DEBUG(7, "Directory to queue to is (%s)\n", svdcfile.sys);
122 
123 			/* place any and all D. files related to the
124 			** C. file in the proper spool area.
125 			*/
126 
127 			putdfiles(svdcfile);
128 
129 			/* Now queue the C. file */
130 
131 			wfcommit(svdcfile.file, svdcfile.file, svdcfile.sys);
132 		}
133 		closedir(machdir);
134 	}
135 	closedir(spooldir);
136 	return (0);
137 }
138 /* a dummy cleanup function to satisfy a .o file */
139 void cleanup() {}
140