3 * Shared routines for playing with list membership.
5 * Copyright (C) 1999 by the Massachusetts Institute of Technology
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
13 #include "mrclient-internal.h"
24 int mrcl_validate_string_member(char *str)
26 char *p, *lname, *ret;
28 for (ret = str; *ret; ret++)
32 mrcl_set_message("STRING \"%s\" contains control characters, "
33 "which are not allowed.", str);
41 char *host = canonicalize_hostname(strdup(++p));
43 if (mailtype(host) != MAILTYPE_SMTP)
47 *strchr(str, '@') = '\0';
48 mrcl_set_message("STRING \"%s\" should be USER or LIST \"%s\" "
49 "because it is a local name.", lname, str);
55 else if (!strpbrk(str, "%!"))
57 mrcl_set_message("STRING \"%s\" is not a foreign mail address.\nAdding "
58 "it to a mailing list may cause the list to break.",
67 int mrcl_validate_kerberos_member(char *str, char **ret)
71 krb5_context context = NULL;
72 char *default_realm = NULL;
76 for (p = str; *p; p++)
78 if (isspace(*p) || *p == ',')
80 mrcl_set_message("KERBEROS member \"%s\" may not contain whitespace "
89 /* An IP address is not a Kerberos principal, but we allow it
92 if (strtoul(str, &p, 10) < 256 && (*p == '.') &&
93 strtoul(p + 1, &p, 10) < 256 && (*p == '.') &&
94 strtoul(p + 1, &p, 10) < 256 && (*p == '.') &&
95 strtoul(p + 1, &p, 10) < 256 && !*p)
101 code = krb5_init_context(&context);
105 code = krb5_get_default_realm(context, &default_realm);
109 *ret = malloc(strlen(str) + strlen(default_realm) + 2);
110 sprintf(*ret, "%s@%s", str, default_realm);
112 mrcl_set_message("Warning: default realm \"%s\" added to principal "
113 "\"%s\"", default_realm, str);
119 krb5_free_context(context);
125 /* Check capitalization. */
127 p = strchr(*ret, '@');
133 mrcl_set_message("Warning: set realm in \"%s\" to all caps.", *ret);