home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * UUCP.c written by William Loftus
- * Copyright 1988 by William Loftus. All rights reserved.
- *
- * $Header: Beta:src/uucp/src/uucico/RCS/uucp.c,v 1.1 90/02/02 11:56:13 dillon Exp Locker: dillon $
- *
- * Heirarchical Spool Conversion 1 Dec 93,
- * Mike J. Bruins. bruins@hal9000.apana.org.au
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "version.h"
- #include <log.h>
- #include "protos.h"
- #include <owndevunit.h>
-
- IDENT(".02");
-
- char to_buf[128];
- char from_buf[128];
- char path[128];
- char user[16];
-
- char command_file[128];
- int seq;
- struct Library *OwnDevUnitBase;
-
- void BuildReceiveFile();
- void BuildSendFile();
- void read_ctl();
- void myexit(void);
- char *expand_file();
-
- #define TRUE 1
- #define FALSE 0
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- int to_bang, from_bang;
-
- LogProgram = "uucp";
- LogWho = GetUserName();
-
- if (argc != 3) {
- printf("Usage: UUCP from_file to_file\n");
- exit(1);
- } else {
- strcat(from_buf, argv[1]);
- strcat(to_buf, argv[2]);
- }
- if ((OwnDevUnitBase = OpenLibrary(ODU_NAME, 0)) == NULL) {
- printf("Unable to open %s\n", ODU_NAME);
- exit(20);
- }
-
- getcwd(path,128);
-
- if (chdir(GetConfigDir(UUSPOOL))) {
- printf("Couldn't change current working directory to %s\n", GetConfigDir(UUSPOOL));
- exit(1);
- }
-
- read_ctl();
-
- seq = GetSequence(2);
- if (seq < 0) {
- chdir(path);
- exit(1);
- }
-
- from_bang = (int)strchr(from_buf,'!');
- to_bang = (int)strchr(to_buf,'!');
-
- if (from_bang && to_bang) {
- printf("Can not specify a remote system in both arguments.\n");
- chdir(path);
- exit(1);
- }
-
- if (from_bang) {
- BuildReceiveFile();
- }
-
- if (to_bang) {
- BuildSendFile();
- }
-
- chdir(path);
- return(0);
- }
-
- void
- myexit()
- {
- UnLockFiles();
-
- if (OwnDevUnitBase) {
- CloseLibrary(OwnDevUnitBase);
- OwnDevUnitBase = NULL;
- }
- }
-
- void
- BuildSendFile()
- {
- FILE *fp;
- char system_name[32],dir[256];
- int bang;
-
- strcpy(from_buf,expand_file(from_buf));
-
- bang = (int)strchr(to_buf,'!');
- bang = bang - (int)to_buf;
-
- strncpy(system_name,to_buf,bang);
-
- system_name[bang] = '\0';
-
- if (!is_in_L_sys_file(system_name)) {
- printf("System \"%s\" not in L.sys file.\n", system_name);
- chdir(path);
- exit(1);
- }
-
- system_name[7] = '\0';
- strcpy(dir,MakeConfigPath(UUSPOOL,system_name)); /* hierarch - bruins */
- if(dir==NULL || *dir=='\0'){
- ulog(-1,"Can't create spool for \"%s\".",system_name);
- exit(1);
- }
- if(chdir(dir)){
- ulog(-1,"Can't find spool \"%s\", creating.",dir);
- if(mkdir(dir)){
- ulog(-1,"Failed to make spool: \"%s\".",dir);
- exit(1);
- }
- chdir(dir);
- }
-
- sprintf(command_file,"C.%sA%s", system_name, SeqToName(seq++));
- LockFile(command_file);
-
- fp = fopen(command_file,"w");
-
- if (fp) { /* srcnam desnam who flags temp mode who */
- fprintf(fp,"S %s %s %s %s %s %s %s\n",
- from_buf,
- to_buf + bang + 1,
- user,
- "-c",
- from_buf,
- "0666",
- user
- );
- fclose(fp);
- } else {
- UnLockFile(command_file);
- perror(command_file);
- chdir(path);
- exit(1);
- }
- UnLockFile(command_file);
- printf("Command queue for transfer to %s.\n", system_name);
- }
-
- void
- BuildReceiveFile()
- {
- FILE *fp;
- char system_name[32];
- int bang;
-
- strcpy(to_buf,expand_file(to_buf));
-
- bang = (int)strchr(from_buf,'!');
- bang = bang - (int)from_buf;
-
- strncpy(system_name,from_buf,bang);
-
- system_name[bang] = '\0';
-
- if (!is_in_L_sys_file(system_name)) {
- printf("System \"%s\" not in L.sys file.\n", system_name);
- chdir(path);
- exit(1);
- }
-
- system_name[7] = '\0';
-
- sprintf(command_file,"%s/C.%sA%s", /* hierarch - bruins */
- system_name,system_name, SeqToName(seq++));
-
- LockFile(command_file);
-
- fp = fopen(command_file,"w");
- if (fp) {
- /* srcnam desnam who flags */
- fprintf(fp,"R %s %s %s %s\n",
- from_buf + bang + 1,
- to_buf,
- user,
- "-c"
- );
- fclose(fp);
- } else {
- UnLockFile(command_file);
- perror(command_file);
- chdir(path);
- exit(1);
- }
- UnLockFile(command_file);
- printf("Command queue for transfer from %s.\n", system_name);
- }
-
- static char name[128];
-
- char *
- expand_file(file_name)
- char *file_name;
- {
- char *colon;
-
- colon = strchr(file_name,':');
- if ((colon != (char*)NULL) && (colon != file_name)) {
- return(file_name);
- } else {
- if (path[strlen(path)-1] != ':') {
- sprintf(name,"%s/%s",path,file_name);
- return name;
- } else {
- sprintf(name,"%s%s",path,file_name);
- return name;
- }
- }
- }
-
- #define CTL_DELIM " \t\r\n"
-
- /*
- * Read the control file and grab a few parameters.
- */
-
- void
- read_ctl()
- {
- FILE *fd;
- static char buf[128];
-
- if (! (fd = fopen(MakeConfigPath(UULIB, "Config"), "r"))) {
- printf("Can't Find config file.\n");
- chdir(path);
- exit(3);
- }
-
- while (NULL != fgets(buf, sizeof buf, fd)) {
- if (strncmp(buf, "UserName", 8) == 0)
- strcpy(user, strtok(&buf[9], CTL_DELIM) ) ;
- }
- fclose(fd);
- }
-
-
-