xref: /illumos-gate/usr/src/cmd/bnu/bnuconvert.c (revision 7a6d80f1660abd4755c68cbd094d4a914681d26e)
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 #include	"uucp.h"
31 
32 int
33 main(argc, argv)
34 int argc;
35 char **argv;
36 {
37 	char fdgrade();
38 	DIR *machdir, *spooldir;
39 	char machname[MAXFULLNAME];
40 	char file1[NAMESIZE+1], file2[NAMESIZE+1];
41 	struct cs_struct svdcfile;
42 	int c;
43 
44 	(void) strcpy(Progname, "bnuconvert");
45 
46 	Uid = getuid();
47 	Euid = geteuid();
48 	if (Uid == 0)
49 		(void) setuid(UUCPUID);
50 
51 	while ((c = getopt(argc, argv, "x:")) != EOF)
52 		switch(c) {
53 		case 'x':
54 			Debug = atoi(optarg);
55 			if (Debug < 0)
56 				Debug = 1;
57 			break;
58 		default:
59 			(void) fprintf(stderr, "usage: bnuconvert [-xLEVEL]\n");
60 			exit(-1);
61 		}
62 
63 	DEBUG(5, "Progname (%s): STARTED\n", Progname);
64 
65 	/* find the default directory to queue to */
66 
67 	if (eaccess(GRADES, 04) != -1)
68 		svdcfile.grade = fdgrade();
69 	else
70 		svdcfile.grade = D_QUEUE;
71 
72 	DEBUG(5, "All jobs will be placed in directory (%c) ", svdcfile.grade);
73 	DEBUG(5, "under each remote name in the spool area.%c\n", NULLCHAR);
74 
75 	if ((spooldir = opendir(SPOOL)) == NULL) {
76 		(void) fprintf(stderr, "CAN'T OPEN (%s): errno (%d)\n",
77 			SPOOL, errno);
78 		exit(1);
79 	}
80 
81 	while (gdirf(spooldir, file1, SPOOL)) {
82 
83 		(void) sprintf(Rmtname, "%s", file1);
84 		(void) sprintf(machname, "%s/%s", SPOOL, file1);
85 		DEBUG(9, "File1 is (%s)\n", file1);
86 		DEBUG(9, "Rmtname is (%s)\n", Rmtname);
87 		DEBUG(9, "Machname is (%s)\n", machname);
88 
89 		if (chdir(machname) != 0) {
90 			(void) fprintf(stderr, "CAN'T CHDIR (%s): errno (%d)\n",
91 				machname, errno);
92 			exit(1);
93 		}
94 
95 		if ((machdir = opendir(machname)) == NULL) {
96 			(void) fprintf(stderr, "CAN'T OPEN (%s): errno (%d)\n",
97 				machname, errno);
98 				continue;
99 		}
100 
101 		DEBUG(7, "Directory: %s\n", machname);
102 
103 		while (gnamef(machdir, file2) == TRUE) {
104 
105 			DEBUG(9, "File read from (%s) ", machname);
106 			DEBUG(9, "is (%s)\n", file2);
107 
108 			if (!EQUALSN(file2, "C.",2))
109 				continue;
110 
111 			/* build a saved C. file structure */
112 
113 			(void) strncpy(svdcfile.file, file2, NAMESIZE-1);
114 			(void) sprintf(svdcfile.sys, "%s/%c", Rmtname, svdcfile.grade);
115 
116 			DEBUG(9, "Rmtname is (%s)\n", Rmtname);
117 			DEBUG(9, "Default directory to queue to is (%c)\n", svdcfile.grade);
118 			DEBUG(7, "Directory to queue to is (%s)\n", svdcfile.sys);
119 
120 			/* place any and all D. files related to the
121 			** C. file in the proper spool area.
122 			*/
123 
124 			putdfiles(svdcfile);
125 
126 			/* Now queue the C. file */
127 
128 			wfcommit(svdcfile.file, svdcfile.file, svdcfile.sys);
129 		}
130 		closedir(machdir);
131 	}
132 	closedir(spooldir);
133 	return (0);
134 }
135 /* a dummy cleanup function to satisfy a .o file */
136 void cleanup() {}
137