1 /*
2 * (C) Maint Laboratory 2003-2004
3 * Author: Elohin Igor'
4 * e-mail: maint@unona.ru
5 * fido : 2:5070/222.52
6 * URL : http://maint.unona.ru
7 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <dirent.h>
12 #include <errno.h>
13 #include "../common.h"
14 #include "../config.h"
15
16 #ifdef _BSD
17 #include <limits.h>
18 #endif
19
20 int verbose;
21 char *prgname;
22 void usage(void);
23 void help(void);
24 char *version = "send-fidogate"VERSION;
25
main(int argc,char * argv[])26 int main(int argc, char *argv[])
27 {
28 struct dirent *dir;
29 DIR *dfd;
30 char fullpath[PATH_MAX];
31 int i;
32 char c;
33 char cmd[PATH_MAX];
34 char buf[512];
35 FILE *fd;
36 unsigned char flagFOUND;
37
38 prgname = strrchr(argv[0], '/');
39 if (prgname == NULL)
40 prgname = argv[0];
41 else
42 prgname++;
43
44 readcfg();
45 loginit("send-fidogate", util_logdir);
46 verbose = 0;
47 if (argc > 1) {
48 for (i = 1; i < argc && argv[i][0] == '-'; i++) {
49 c = argv[i][1];
50 switch (c) {
51 case 'h':
52 help();
53 exit(0);
54 case 'v':
55 verbose = 1;
56 break;
57 default:
58 usage();
59 }
60 }
61 }
62 if (setgid(getegid()) < 0) {
63 myerror("cannot setgid to %d", getegid());
64 exit(1);
65 }
66 if (setuid(geteuid()) < 0) {
67 myerror("cannot setuid to %d", geteuid());
68 exit(1);
69 }
70 if ((dfd = opendir(outgoing)) == NULL) {
71 myerror("%s \'%s\'\n", strerror(errno), outgoing);
72 return 1;
73 }
74 i = 0;
75 while ((dir = readdir(dfd)) != NULL) {
76 if (strcmp(dir->d_name, ".") == 0 ||
77 strcmp(dir->d_name, "..") == 0)
78 continue;
79 snprintf(fullpath, sizeof(fullpath), "%s/%s", outgoing, dir->d_name);
80 if((fd = fopen(fullpath, "r")) == NULL){
81 myerror("Can't open \'%s\' (%s)\n", fullpath, strerror(errno));
82 continue;
83 }
84 flagFOUND = 0;
85 while(fgets(buf, 512, fd)){
86 if(strncmp(buf, "Newsgroups: ", 12) == 0){
87 if(isfidogroup(&buf[12])){
88 flagFOUND = 1;
89 break;
90 }
91 }
92 }
93 if(!flagFOUND){
94 myerror("Newsgroups not found\n");
95 fclose(fd);
96 continue;
97 }
98 fclose(fd);
99 i++;
100 if (verbose)
101 notice("send %s started", dir->d_name);
102 snprintf(cmd, sizeof(cmd), "%s %s/%s | %s",
103 delete_ctrl_d, outgoing, dir->d_name, rfc2ftn);
104 if (system(cmd)) {
105 if (verbose)
106 notice("send %s failed (%s)", dir->d_name, cmd);
107 } else {
108 if (verbose)
109 notice("send %s ok", dir->d_name);
110 if (remove(fullpath)) {
111 myerror("%s \'%s\'\n", strerror(errno), fullpath);
112 }
113 }
114 }
115 if (verbose)
116 notice("Sending %d files", i);
117 closedir(dfd);
118 fflush(stderr);
119 logclose();
120 exit(0);
121 }
usage(void)122 void usage(void)
123 {
124 printf("usage: %s [-h][-v]", prgname);
125 }
help(void)126 void help(void)
127 {
128 printf("\t%s\n\t-------------------\n"
129 "usage: send-fidogate [-options]\n"
130 "options:\n"
131 "\t-h this help\n"
132 "\t-v verbose\n"
133 "\n"
134 "Copyright (C) 2003-2004 Igor' Elohin <maint@unona.ru>\n"
135 "-------------------------------------------------------------\n"
136 "Eagle's send-fidogate comes with ABSOLUTELY NO WARRANTY;\n"
137 "This is free software, and you are welcome to redistribute it\n"
138 "under certain conditions.\n",
139 version);
140 }
141
142