1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
|
#include <sys/param.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <netdb.h>
#include <errno.h>
#include <unistd.h>
#include <stdarg.h>
#include <sys/file.h>
#include <syslog.h>
#include <glib.h>
#include "config.h"
#ifdef HAVE_LIBUTIL_H
#include <libutil.h>
#endif
#include "util.h"
#include "cfg_file.h"
sig_atomic_t do_reopen_log = 0;
int
event_make_socket_nonblocking (int fd)
{
if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
return -1;
}
return 0;
}
static int
make_socket_ai (struct addrinfo *ai)
{
struct linger linger;
int fd, on = 1, r;
int serrno;
/* Create listen socket */
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd == -1) {
return (-1);
}
if (event_make_socket_nonblocking(fd) < 0)
goto out;
if (fcntl(fd, F_SETFD, 1) == -1) {
goto out;
}
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on));
linger.l_onoff = 1;
linger.l_linger = 5;
setsockopt(fd, SOL_SOCKET, SO_LINGER, (void *)&linger, sizeof(linger));
r = bind(fd, ai->ai_addr, ai->ai_addrlen);
if (r == -1) {
if (errno != EINPROGRESS) {
goto out;
}
}
return (fd);
out:
serrno = errno;
close(fd);
errno = serrno;
return (-1);
}
int
make_socket (const char *address, u_short port)
{
int fd;
struct addrinfo ai, *aitop = NULL;
char strport[NI_MAXSERV];
int ai_result;
memset (&ai, 0, sizeof (ai));
ai.ai_family = AF_INET;
ai.ai_socktype = SOCK_STREAM;
ai.ai_flags = AI_PASSIVE;
snprintf (strport, sizeof (strport), "%d", port);
if ((ai_result = getaddrinfo (address, strport, &ai, &aitop)) != 0) {
return (-1);
}
fd = make_socket_ai (aitop);
freeaddrinfo (aitop);
return (fd);
}
int
make_unix_socket (const char *path, struct sockaddr_un *addr)
{
size_t len = strlen (path);
int sock;
if (len > sizeof (addr->sun_path) - 1) return -1;
#ifdef FREEBSD
addr->sun_len = sizeof (struct sockaddr_un);
#endif
addr->sun_family = AF_UNIX;
strncpy (addr->sun_path, path, len);
sock = socket (PF_LOCAL, SOCK_STREAM, 0);
if (sock != -1) {
if (bind (sock, (struct sockaddr *) addr, sizeof (struct sockaddr_un)) == -1) return -1;
}
return sock;
}
void
read_cmd_line (int argc, char **argv, struct config_file *cfg)
{
int ch;
while ((ch = getopt(argc, argv, "hfc:")) != -1) {
switch (ch) {
case 'f':
cfg->no_fork = 1;
break;
case 'c':
if (optarg && cfg->cfg_name) {
cfg->cfg_name = memory_pool_strdup (cfg->cfg_pool, optarg);
}
break;
case 'h':
case '?':
default:
/* Show help message and exit */
printf ("Rspamd version " RVERSION "\n"
"Usage: rspamd [-h] [-n] [-f] [-c config_file]\n"
"-h: This help message\n"
"-f: Do not daemonize main process\n"
"-c: Specify config file (./rspamd.conf is used by default)\n");
exit (0);
break;
}
}
}
int
write_pid (struct rspamd_main *main)
{
pid_t pid;
main->pfh = pidfile_open (main->cfg->pid_file, 0644, &pid);
if (main->pfh == NULL) {
return -1;
}
pidfile_write (main->pfh);
return 0;
}
void
init_signals (struct sigaction *signals, sig_t sig_handler)
{
/* Setting up signal handlers */
/* SIGUSR1 - reopen config file */
/* SIGUSR2 - worker is ready for accept */
sigemptyset(&signals->sa_mask);
sigaddset(&signals->sa_mask, SIGTERM);
sigaddset(&signals->sa_mask, SIGINT);
sigaddset(&signals->sa_mask, SIGHUP);
sigaddset(&signals->sa_mask, SIGCHLD);
sigaddset(&signals->sa_mask, SIGUSR1);
sigaddset(&signals->sa_mask, SIGUSR2);
signals->sa_handler = sig_handler;
sigaction (SIGTERM, signals, NULL);
sigaction (SIGINT, signals, NULL);
sigaction (SIGHUP, signals, NULL);
sigaction (SIGCHLD, signals, NULL);
sigaction (SIGUSR1, signals, NULL);
sigaction (SIGUSR2, signals, NULL);
}
void
pass_signal_worker (struct workq *workers, int signo)
{
struct rspamd_worker *cur;
TAILQ_FOREACH (cur, workers, next) {
kill (cur->pid, signo);
}
}
void convert_to_lowercase (char *str, unsigned int size)
{
while (size--) {
*str = tolower (*str);
str ++;
}
}
#ifndef HAVE_SETPROCTITLE
static char *title_buffer = 0;
static size_t title_buffer_size = 0;
static char *title_progname, *title_progname_full;
int
setproctitle (const char *fmt, ...)
{
if (!title_buffer || !title_buffer_size) {
errno = ENOMEM;
return -1;
}
memset (title_buffer, '\0', title_buffer_size);
ssize_t written;
if (fmt) {
ssize_t written2;
va_list ap;
written = snprintf (title_buffer, title_buffer_size, "%s: ", title_progname);
if (written < 0 || (size_t) written >= title_buffer_size)
return -1;
va_start (ap, fmt);
written2 =
vsnprintf (title_buffer + written,
title_buffer_size - written, fmt, ap);
va_end (ap);
if (written2 < 0
|| (size_t) written2 >= title_buffer_size - written)
return -1;
} else {
written =
snprintf (title_buffer, title_buffer_size, "%s",
title_progname);
if (written < 0 || (size_t) written >= title_buffer_size)
return -1;
}
written = strlen (title_buffer);
memset (title_buffer + written, '\0', title_buffer_size - written);
return 0;
}
/*
It has to be _init function, because __attribute__((constructor))
functions gets called without arguments.
*/
int
init_title (int argc, char *argv[], char *envp[])
{
char *begin_of_buffer = 0, *end_of_buffer = 0;
int i;
for (i = 0; i < argc; ++i) {
if (!begin_of_buffer)
begin_of_buffer = argv[i];
if (!end_of_buffer || end_of_buffer + 1 == argv[i])
end_of_buffer = argv[i] + strlen (argv[i]);
}
for (i = 0; envp[i]; ++i) {
if (!begin_of_buffer)
begin_of_buffer = envp[i];
if (!end_of_buffer || end_of_buffer + 1 == envp[i])
end_of_buffer = envp[i] + strlen(envp[i]);
}
if (!end_of_buffer)
return 0;
char **new_environ = g_malloc ((i + 1) * sizeof (envp[0]));
if (!new_environ)
return 0;
for (i = 0; envp[i]; ++i) {
if (!(new_environ[i] = g_strdup (envp[i])))
goto cleanup_enomem;
}
new_environ[i] = 0;
if (program_invocation_name) {
title_progname_full = g_strdup (program_invocation_name);
if (!title_progname_full)
goto cleanup_enomem;
char *p = strrchr (title_progname_full, '/');
if (p)
title_progname = p + 1;
else
title_progname = title_progname_full;
program_invocation_name = title_progname_full;
program_invocation_short_name = title_progname;
}
environ = new_environ;
title_buffer = begin_of_buffer;
title_buffer_size = end_of_buffer - begin_of_buffer;
return 0;
cleanup_enomem:
for (--i; i >= 0; --i) {
g_free (new_environ[i]);
}
g_free (new_environ);
return 0;
}
#endif
#ifndef HAVE_PIDFILE
extern char * __progname;
static int _pidfile_remove (struct pidfh *pfh, int freeit);
static int
pidfile_verify (struct pidfh *pfh)
{
struct stat sb;
if (pfh == NULL || pfh->pf_fd == -1)
return (-1);
/*
* Check remembered descriptor.
*/
if (fstat (pfh->pf_fd, &sb) == -1)
return (errno);
if (sb.st_dev != pfh->pf_dev || sb.st_ino != pfh->pf_ino)
return -1;
return 0;
}
static int
pidfile_read (const char *path, pid_t *pidptr)
{
char buf[16], *endptr;
int error, fd, i;
fd = open (path, O_RDONLY);
if (fd == -1)
return (errno);
i = read (fd, buf, sizeof(buf) - 1);
error = errno; /* Remember errno in case close() wants to change it. */
close (fd);
if (i == -1)
return error;
else if (i == 0)
return EAGAIN;
buf[i] = '\0';
*pidptr = strtol (buf, &endptr, 10);
if (endptr != &buf[i])
return EINVAL;
return 0;
}
struct pidfh *
pidfile_open (const char *path, mode_t mode, pid_t *pidptr)
{
struct pidfh *pfh;
struct stat sb;
int error, fd, len, count;
struct timespec rqtp;
pfh = g_malloc (sizeof(*pfh));
if (pfh == NULL)
return NULL;
if (path == NULL)
len = snprintf (pfh->pf_path, sizeof(pfh->pf_path),
"/var/run/%s.pid", __progname);
else
len = snprintf (pfh->pf_path, sizeof(pfh->pf_path),
"%s", path);
if (len >= (int)sizeof (pfh->pf_path)) {
g_free (pfh);
errno = ENAMETOOLONG;
return NULL;
}
/*
* Open the PID file and obtain exclusive lock.
* We truncate PID file here only to remove old PID immediatelly,
* PID file will be truncated again in pidfile_write(), so
* pidfile_write() can be called multiple times.
*/
fd = open (pfh->pf_path,
O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode);
flock (fd, LOCK_EX | LOCK_NB);
if (fd == -1) {
count = 0;
rqtp.tv_sec = 0;
rqtp.tv_nsec = 5000000;
if (errno == EWOULDBLOCK && pidptr != NULL) {
again:
errno = pidfile_read (pfh->pf_path, pidptr);
if (errno == 0)
errno = EEXIST;
else if (errno == EAGAIN) {
if (++count <= 3) {
nanosleep (&rqtp, 0);
goto again;
}
}
}
g_free (pfh);
return NULL;
}
/*
* Remember file information, so in pidfile_write() we are sure we write
* to the proper descriptor.
*/
if (fstat (fd, &sb) == -1) {
error = errno;
unlink (pfh->pf_path);
close (fd);
g_free (pfh);
errno = error;
return NULL;
}
pfh->pf_fd = fd;
pfh->pf_dev = sb.st_dev;
pfh->pf_ino = sb.st_ino;
return pfh;
}
int
pidfile_write (struct pidfh *pfh)
{
char pidstr[16];
int error, fd;
/*
* Check remembered descriptor, so we don't overwrite some other
* file if pidfile was closed and descriptor reused.
*/
errno = pidfile_verify (pfh);
if (errno != 0) {
/*
* Don't close descriptor, because we are not sure if it's ours.
*/
return -1;
}
fd = pfh->pf_fd;
/*
* Truncate PID file, so multiple calls of pidfile_write() are allowed.
*/
if (ftruncate (fd, 0) == -1) {
error = errno;
_pidfile_remove (pfh, 0);
errno = error;
return -1;
}
snprintf (pidstr, sizeof(pidstr), "%u", getpid ());
if (pwrite (fd, pidstr, strlen (pidstr), 0) != (ssize_t)strlen (pidstr)) {
error = errno;
_pidfile_remove (pfh, 0);
errno = error;
return -1;
}
return 0;
}
int
pidfile_close (struct pidfh *pfh)
{
int error;
error = pidfile_verify (pfh);
if (error != 0) {
errno = error;
return -1;
}
if (close (pfh->pf_fd) == -1)
error = errno;
g_free (pfh);
if (error != 0) {
errno = error;
return -1;
}
return 0;
}
static int
_pidfile_remove (struct pidfh *pfh, int freeit)
{
int error;
error = pidfile_verify (pfh);
if (error != 0) {
errno = error;
return -1;
}
if (unlink (pfh->pf_path) == -1)
error = errno;
if (flock (pfh->pf_fd, LOCK_UN) == -1) {
if (error == 0)
error = errno;
}
if (close (pfh->pf_fd) == -1) {
if (error == 0)
error = errno;
}
if (freeit)
g_free (pfh);
else
pfh->pf_fd = -1;
if (error != 0) {
errno = error;
return -1;
}
return 0;
}
int
pidfile_remove (struct pidfh *pfh)
{
return (_pidfile_remove (pfh, 1));
}
#endif
/*
* Functions for parsing expressions
*/
struct expression_stack {
char op;
struct expression_stack *next;
};
/*
* Push operand or operator to stack
*/
static struct expression_stack*
push_expression_stack (memory_pool_t *pool, struct expression_stack *head, char op)
{
struct expression_stack *new;
new = memory_pool_alloc (pool, sizeof (struct expression_stack));
new->op = op;
new->next = head;
return new;
}
/*
* Delete symbol from stack, return pointer to operand or operator (casted to void* )
*/
static char
delete_expression_stack (struct expression_stack **head)
{
struct expression_stack *cur;
char res;
if(*head == NULL) return 0;
cur = *head;
res = cur->op;
*head = cur->next;
return res;
}
/*
* Return operation priority
*/
static int
logic_priority (char a)
{
switch (a) {
case '!':
return 3;
case '|':
case '&':
return 2;
case '(':
return 1;
default:
return 0;
}
}
/*
* Return 0 if symbol is not operation symbol (operand)
* Return 1 if symbol is operation symbol
*/
static int
is_operation_symbol (char a)
{
switch (a) {
case '!':
case '&':
case '|':
case '(':
case ')':
return 1;
default:
return 0;
}
}
static void
insert_expression (memory_pool_t *pool, struct expression **head, int type, char op, void *operand)
{
struct expression *new, *cur;
new = memory_pool_alloc (pool, sizeof (struct expression));
new->type = type;
if (new->type == EXPR_OPERAND) {
new->content.operand = operand;
}
else {
new->content.operation = op;
}
new->next = NULL;
if (!*head) {
*head = new;
}
else {
cur = *head;
while (cur->next) {
cur = cur->next;
}
cur->next = new;
}
}
/*
* Make inverse polish record for specified expression
* Memory is allocated from given pool
*/
struct expression*
parse_expression (memory_pool_t *pool, char *line)
{
struct expression *expr = NULL;
struct expression_stack *stack = NULL;
char *p, *c, *str, op, in_regexp = 0;
if (line == NULL || pool == NULL) {
return NULL;
}
p = line;
c = p;
while (*p) {
if (is_operation_symbol (*p) && !in_regexp) {
if (c != p) {
/* Copy operand */
str = memory_pool_alloc (pool, p - c + 1);
g_strlcpy (str, c, (p - c + 1));
insert_expression (pool, &expr, EXPR_OPERAND, 0, str);
}
if (*p == ')') {
if (stack == NULL) {
return NULL;
}
/* Pop all operators from stack to nearest '(' or to head */
while (stack->op != '(') {
op = delete_expression_stack (&stack);
if (op != '(') {
insert_expression (pool, &expr, EXPR_OPERATION, op, NULL);
}
}
}
else if (*p == '(') {
/* Push it to stack */
stack = push_expression_stack (pool, stack, *p);
}
else {
if (stack == NULL) {
stack = push_expression_stack (pool, stack, *p);
}
/* Check priority of logic operation */
else {
if (logic_priority (stack->op) < logic_priority (*p)) {
stack = push_expression_stack (pool, stack, *p);
}
else {
/* Pop all operations that have higher priority than this one */
while((stack != NULL) && (logic_priority (stack->op) >= logic_priority (*p))) {
op = delete_expression_stack (&stack);
if (op != '(') {
insert_expression (pool, &expr, EXPR_OPERATION, op, NULL);
}
}
stack = push_expression_stack (pool, stack, *p);
}
}
}
c = p + 1;
}
if (*p == '/' && (p == line || *(p - 1) != '\\')) {
in_regexp = !in_regexp;
}
p++;
}
/* Write last operand if it exists */
if (c != p) {
/* Copy operand */
str = memory_pool_alloc (pool, p - c + 1);
g_strlcpy (str, c, (p - c + 1));
insert_expression (pool, &expr, EXPR_OPERAND, 0, str);
}
/* Pop everything from stack */
while(stack != NULL) {
op = delete_expression_stack (&stack);
if (op != '(') {
insert_expression (pool, &expr, EXPR_OPERATION, op, NULL);
}
}
return expr;
}
/* Logging utility functions */
int
open_log (struct config_file *cfg)
{
switch (cfg->log_type) {
case RSPAMD_LOG_CONSOLE:
/* Do nothing with console */
return 0;
case RSPAMD_LOG_SYSLOG:
openlog ("rspamd", LOG_NDELAY | LOG_PID, cfg->log_facility);
return 0;
case RSPAMD_LOG_FILE:
cfg->log_fd = open (cfg->log_file, O_CREAT | O_WRONLY | O_APPEND, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
if (cfg->log_fd == -1) {
msg_err ("open_log: cannot open desired log file: %s, %m", cfg->log_file);
return -1;
}
return 0;
}
}
int
reopen_log (struct config_file *cfg)
{
do_reopen_log = 0;
switch (cfg->log_type) {
case RSPAMD_LOG_CONSOLE:
/* Do nothing with console */
return 0;
case RSPAMD_LOG_SYSLOG:
closelog ();
break;
case RSPAMD_LOG_FILE:
close (cfg->log_fd);
break;
}
return open_log (cfg);
}
void
syslog_log_function (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer arg)
{
struct config_file *cfg = (struct config_file *)arg;
if (do_reopen_log) {
reopen_log (cfg);
}
if (log_level <= cfg->log_level) {
if (log_level >= G_LOG_LEVEL_DEBUG) {
syslog (LOG_DEBUG, "%s", message);
}
else if (log_level >= G_LOG_LEVEL_INFO) {
syslog (LOG_INFO, "%s", message);
}
else if (log_level >= G_LOG_LEVEL_WARNING) {
syslog (LOG_WARNING, "%s", message);
}
else if (log_level >= G_LOG_LEVEL_CRITICAL) {
syslog (LOG_ERR, "%s", message);
}
}
}
void
file_log_function (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer arg)
{
struct config_file *cfg = (struct config_file *)arg;
char tmpbuf[128];
int r;
struct iovec out[3];
if (cfg->log_fd == -1) {
return;
}
if (do_reopen_log) {
reopen_log (cfg);
}
if (log_level <= cfg->log_level) {
r = snprintf (tmpbuf, sizeof (tmpbuf), "#%d: %d rspamd ", (int)getpid (), (int)time (NULL));
out[0].iov_base = tmpbuf;
out[0].iov_len = r;
out[1].iov_base = (char *)message;
out[1].iov_len = strlen (message);
out[2].iov_base = "\r\n";
out[2].iov_len = 2;
writev (cfg->log_fd, out, sizeof (out) / sizeof (out[0]));
}
}
/* Replace %r with rcpt value and %f with from value, new string is allocated in pool */
char *
resolve_stat_filename (memory_pool_t *pool, char *pattern, char *rcpt, char *from)
{
int need_to_format = 0, len = 0;
int rcptlen = strlen (rcpt);
int fromlen = strlen (from);
char *c = pattern, *new, *s;
/* Calculate length */
while (*c++) {
if (*c == '%' && *(c + 1) == 'r') {
len += rcptlen;
c += 2;
need_to_format = 1;
continue;
}
else if (*c == '%' && *(c + 1) == 'f') {
len += fromlen;
c += 2;
need_to_format = 1;
continue;
}
len ++;
}
/* Do not allocate extra memory if we do not need to format string */
if (!need_to_format) {
return pattern;
}
/* Allocate new string */
new = memory_pool_alloc (pool, len);
c = pattern;
s = new;
/* Format string */
while (*c ++) {
if (*c == '%' && *(c + 1) == 'r') {
c += 2;
memcpy (s, rcpt, rcptlen);
s += rcptlen;
continue;
}
else if (*c == '%' && *(c + 1) == 'r') {
c += 2;
memcpy (s, from, fromlen);
s += fromlen;
continue;
}
*s ++ = *c;
}
*s = '\0';
return new;
}
/*
* vi:ts=4
*/
|