masqmail

annotate src/expand.c @ 421:f37384470855

Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup. Moved the lockdir out of the spool dir. (When /var/lock is a ramdisk we do well to have the lock files there.) Added the new configure option --with-lockdir to change that location. Nontheless, if we run_as_user, then lock files are always stored in the spool dir directly. Instead of installing the lockdir and piddir at installation time, we create them on startup time now if they are missing. This is necessary if lockdir or piddir are a tmpfs.
author markus schnalke <meillo@marmaro.de>
date Wed, 30 May 2012 09:38:38 +0200
parents b27f66555ba8
children
rev   line source
meillo@367 1 /*
meillo@367 2 ** MasqMail
meillo@367 3 ** Copyright (C) 2000-2001 Oliver Kurth
meillo@367 4 **
meillo@367 5 ** This program is free software; you can redistribute it and/or modify
meillo@367 6 ** it under the terms of the GNU General Public License as published by
meillo@367 7 ** the Free Software Foundation; either version 2 of the License, or
meillo@367 8 ** (at your option) any later version.
meillo@367 9 **
meillo@367 10 ** This program is distributed in the hope that it will be useful,
meillo@367 11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
meillo@367 12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
meillo@367 13 ** GNU General Public License for more details.
meillo@367 14 **
meillo@367 15 ** You should have received a copy of the GNU General Public License
meillo@367 16 ** along with this program; if not, write to the Free Software
meillo@367 17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
meillo@0 18 */
meillo@0 19
meillo@0 20 #include "masqmail.h"
meillo@0 21
meillo@0 22 #define MAX_VAR 50
meillo@0 23
meillo@10 24 GList*
meillo@366 25 var_table_rcpt(GList *var_table, address *rcpt)
meillo@0 26 {
meillo@10 27 gchar *tmp_str;
meillo@0 28
meillo@405 29 var_table = g_list_prepend(var_table,
meillo@405 30 create_pair_string("rcpt_local", rcpt->local_part));
meillo@405 31 var_table = g_list_prepend(var_table,
meillo@405 32 create_pair_string("rcpt_domain", rcpt->domain));
meillo@10 33
meillo@10 34 tmp_str = g_strdup_printf("%s@%s", rcpt->local_part, rcpt->domain);
meillo@405 35 var_table = g_list_prepend(var_table,
meillo@405 36 create_pair_string("rcpt", tmp_str));
meillo@10 37 g_free(tmp_str);
meillo@10 38
meillo@10 39 return var_table;
meillo@0 40 }
meillo@0 41
meillo@10 42 GList*
meillo@366 43 var_table_msg(GList *var_table, message *msg)
meillo@0 44 {
meillo@10 45 address *ret_path = msg->return_path;
meillo@10 46 gchar *tmp_str;
meillo@0 47
meillo@405 48 var_table = g_list_prepend(var_table,
meillo@405 49 create_pair_string("uid", msg->uid));
meillo@405 50 var_table = g_list_prepend(var_table,
meillo@405 51 create_pair_string("received_host",
meillo@405 52 msg->received_host ? msg->received_host : ""));
meillo@405 53 var_table = g_list_prepend(var_table,
meillo@405 54 create_pair_string("ident",
meillo@405 55 msg->ident ? msg->ident : ""));
meillo@405 56 var_table = g_list_prepend(var_table,
meillo@405 57 create_pair_string("return_path_local",
meillo@405 58 ret_path->local_part));
meillo@405 59 var_table = g_list_prepend(var_table,
meillo@405 60 create_pair_string("return_path_domain",
meillo@405 61 ret_path->domain));
meillo@10 62
meillo@405 63 tmp_str = g_strdup_printf("%s@%s",
meillo@405 64 ret_path->local_part, ret_path->domain);
meillo@405 65 var_table = g_list_prepend(var_table,
meillo@405 66 create_pair_string("return_path", tmp_str));
meillo@10 67 g_free(tmp_str);
meillo@10 68
meillo@10 69 return var_table;
meillo@0 70 }
meillo@0 71
meillo@10 72 GList*
meillo@366 73 var_table_conf(GList *var_table)
meillo@0 74 {
meillo@405 75 var_table = g_list_prepend(var_table,
meillo@405 76 create_pair_string("host_name", conf.host_name));
meillo@405 77 var_table = g_list_prepend(var_table,
meillo@405 78 create_pair_string("package", PACKAGE));
meillo@405 79 var_table = g_list_prepend(var_table,
meillo@405 80 create_pair_string("version", VERSION));
meillo@0 81
meillo@10 82 return var_table;
meillo@0 83 }
meillo@0 84
meillo@10 85 gint
meillo@366 86 expand(GList *var_list, gchar *format, gchar *result, gint result_len)
meillo@0 87 {
meillo@10 88 gchar *p = format, *q = result;
meillo@10 89 gchar *vq;
meillo@10 90 gint i = 0;
meillo@10 91 gboolean escape = FALSE;
meillo@0 92
meillo@10 93 while (*p && (i < (result_len - 1))) {
meillo@10 94 if ((*p == '$') && !escape) {
meillo@10 95 gchar *value;
meillo@10 96 gchar var[MAX_VAR + 1];
meillo@10 97 int j = 0;
meillo@0 98
meillo@10 99 p++; /* skip '$' */
meillo@10 100 vq = var;
meillo@0 101
meillo@10 102 if (*p == '{') {
meillo@10 103 /* ${var} style */
meillo@10 104 p++; /* skip '{' */
meillo@10 105 while (*p && (*p != '}') && (j < MAX_VAR)) {
meillo@10 106 *(vq++) = *(p++);
meillo@10 107 j++;
meillo@10 108 }
meillo@10 109 p++;
meillo@10 110 } else {
meillo@10 111 /* $var style */
meillo@405 112 while (*p && (isalnum(*p) || (*p=='_') ||
meillo@405 113 (*p=='-')) && (j < MAX_VAR)) {
meillo@10 114 *(vq++) = *(p++);
meillo@10 115 j++;
meillo@10 116 }
meillo@10 117 }
meillo@15 118 *vq = '\0';
meillo@10 119
meillo@10 120 if (j < MAX_VAR) {
meillo@10 121 /* search var */
meillo@10 122 value = (gchar *) table_find(var_list, var);
meillo@10 123 if (value) {
meillo@10 124 gchar *vp = value;
meillo@10 125 while (*vp && (i < (result_len - 1))) {
meillo@10 126 *(q++) = *(vp++);
meillo@10 127 i++;
meillo@10 128 }
meillo@10 129 }
meillo@10 130 }
meillo@10 131 } else {
meillo@10 132 if ((*p == '\\') && (!escape)) {
meillo@10 133 escape = TRUE;
meillo@10 134 } else {
meillo@10 135 *(q++) = *p;
meillo@10 136 i++;
meillo@10 137 escape = FALSE;
meillo@10 138 }
meillo@10 139 p++;
meillo@10 140 }
meillo@0 141 }
meillo@15 142 *q = '\0';
meillo@0 143
meillo@10 144 if (i >= (result_len - 1))
meillo@10 145 return -3;
meillo@0 146
meillo@10 147 return i;
meillo@0 148 }