4 * This file contains functions which handle the mapping of Internet addresses
5 * to users on the Citadel system.
16 #include <sys/types.h>
24 #include "sysdep_decls.h"
25 #include "citserver.h"
29 #include "internet_addressing.h"
34 * Return 0 if a given string fuzzy-matches a Citadel user account
36 * FIX ... this needs to be updated to match any and all address syntaxes.
38 int fuzzy_match(struct usersupp *us, char *matchstring) {
41 for (a=0; a<strlen(us->fullname); ++a) {
42 if (!strncasecmp(&us->fullname[a],
43 matchstring, strlen(matchstring))) {
54 * Split an RFC822-style address into userid, host, and full name
55 * (Originally from citmail.c, and unchanged so far)
58 void process_rfc822_addr(char *rfc822, char *user, char *node, char *name)
62 /* extract full name - first, it's From minus <userid> */
64 for (a = 0; a < strlen(name); ++a) {
67 strcpy(&name[a], &name[a + 1]);
68 } while ((strlen(name) > 0) && (name[a] != '>'));
69 strcpy(&name[a], &name[a + 1]);
72 /* strip anything to the left of a bang */
73 while ((strlen(name) > 0) && (haschar(name, '!') > 0))
74 strcpy(name, &name[1]);
76 /* and anything to the right of a @ or % */
77 for (a = 0; a < strlen(name); ++a) {
84 /* but if there are parentheses, that changes the rules... */
85 if ((haschar(rfc822, '(') == 1) && (haschar(rfc822, ')') == 1)) {
87 while ((strlen(name) > 0) && (name[0] != '(')) {
88 strcpy(&name[0], &name[1]);
90 strcpy(&name[0], &name[1]);
91 for (a = 0; a < strlen(name); ++a) {
97 /* but if there are a set of quotes, that supersedes everything */
98 if (haschar(rfc822, 34) == 2) {
100 while ((strlen(name) > 0) && (name[0] != 34)) {
101 strcpy(&name[0], &name[1]);
103 strcpy(&name[0], &name[1]);
104 for (a = 0; a < strlen(name); ++a)
108 /* extract user id */
109 strcpy(user, rfc822);
111 /* first get rid of anything in parens */
112 for (a = 0; a < strlen(user); ++a)
113 if (user[a] == '(') {
115 strcpy(&user[a], &user[a + 1]);
116 } while ((strlen(user) > 0) && (user[a] != ')'));
117 strcpy(&user[a], &user[a + 1]);
119 /* if there's a set of angle brackets, strip it down to that */
120 if ((haschar(user, '<') == 1) && (haschar(user, '>') == 1)) {
121 while ((strlen(user) > 0) && (user[0] != '<')) {
122 strcpy(&user[0], &user[1]);
124 strcpy(&user[0], &user[1]);
125 for (a = 0; a < strlen(user); ++a)
129 /* strip anything to the left of a bang */
130 while ((strlen(user) > 0) && (haschar(user, '!') > 0))
131 strcpy(user, &user[1]);
133 /* and anything to the right of a @ or % */
134 for (a = 0; a < strlen(user); ++a) {
142 /* extract node name */
143 strcpy(node, rfc822);
145 /* first get rid of anything in parens */
146 for (a = 0; a < strlen(node); ++a)
147 if (node[a] == '(') {
149 strcpy(&node[a], &node[a + 1]);
150 } while ((strlen(node) > 0) && (node[a] != ')'));
151 strcpy(&node[a], &node[a + 1]);
153 /* if there's a set of angle brackets, strip it down to that */
154 if ((haschar(node, '<') == 1) && (haschar(node, '>') == 1)) {
155 while ((strlen(node) > 0) && (node[0] != '<')) {
156 strcpy(&node[0], &node[1]);
158 strcpy(&node[0], &node[1]);
159 for (a = 0; a < strlen(node); ++a)
163 /* strip anything to the left of a @ */
164 while ((strlen(node) > 0) && (haschar(node, '@') > 0))
165 strcpy(node, &node[1]);
167 /* strip anything to the left of a % */
168 while ((strlen(node) > 0) && (haschar(node, '%') > 0))
169 strcpy(node, &node[1]);
171 /* reduce multiple system bang paths to node!user */
172 while ((strlen(node) > 0) && (haschar(node, '!') > 1))
173 strcpy(node, &node[1]);
175 /* now get rid of the user portion of a node!user string */
176 for (a = 0; a < strlen(node); ++a)
180 /* strip leading and trailing spaces in all strings */
189 * Back end for convert_internet_address()
190 * (Compares an internet name [buffer1] and stores in [buffer2] if found)
192 void try_name(struct usersupp *us) {
194 if (!strncasecmp(CC->buffer1, "cit", 3))
195 if (atol(&CC->buffer1[3]) == us->usernum)
196 strcpy(CC->buffer2, us->fullname);
198 if (!collapsed_strcmp(CC->buffer1, us->fullname))
199 strcpy(CC->buffer2, us->fullname);
201 if (us->uid != BBSUID)
202 if (!strcasecmp(CC->buffer1, getpwuid(us->uid)->pw_name))
203 strcpy(CC->buffer2, us->fullname);
208 * Convert an Internet email address to a Citadel user/host combination
210 int convert_internet_address(char *destuser, char *desthost, char *source)
217 process_rfc822_addr(source, user, node, name);
219 /* Map the FQDN to a Citadel node name
220 * FIX ... we have to check for all known aliases for the local
221 * system, and also handle gateway domains, etc. etc.
223 if (!strcasecmp(node, config.c_fqdn)) {
224 strcpy(node, config.c_nodename);
227 /* Return an error condition if the node is not known.
228 * FIX ... make this work for non-local systems
230 if (strcasecmp(node, config.c_nodename)) {
234 /* Now try to resolve the name
235 * FIX ... do the multiple-addresses thing
237 if (!strcasecmp(node, config.c_nodename)) {
238 strcpy(destuser, user);
239 strcpy(desthost, config.c_nodename);
240 strcpy(CC->buffer1, user);
241 strcpy(CC->buffer2, "");
242 ForEachUser(try_name);
243 if (strlen(CC->buffer2) == 0) return(2);
244 strcpy(destuser, CC->buffer2);
248 return(3); /* unknown error */