]> andersk Git - moira.git/blame - clients/lib/member.c
Put more brains into libmrclient's mrcl_validate_kerberos_member():
[moira.git] / clients / lib / member.c
CommitLineData
d5a7ea17 1/* $Id$
2 *
3 * Shared routines for playing with list membership.
4 *
5 * Copyright (C) 1999 by the Massachusetts Institute of Technology
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
8 */
9
10#include <mit-copyright.h>
11#include <moira.h>
12#include <mrclient.h>
13#include "mrclient-internal.h"
14
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
655a8467 18#include <ctype.h>
d5a7ea17 19
20#include <krb.h>
21
22RCSID("$Header$");
23
24static char default_realm[REALM_SZ];
25
26int mrcl_validate_string_member(char *str)
27{
655a8467 28 char *p, *lname, *ret;
29
30 for (ret = str; *ret; ret++)
31 {
32 if (iscntrl(*ret))
33 {
34 mrcl_set_message("STRING \"%s\" contains control characters, "
35 "which are not allowed.", str);
36 return MRCL_REJECT;
37 }
38 }
d5a7ea17 39
40 p = strchr(str, '@');
41 if (p)
42 {
43 char *host = canonicalize_hostname(strdup(++p));
44
45 if (mailtype(host) != MAILTYPE_SMTP)
46 {
47 free(host);
48 lname = strdup(str);
49 *strchr(str, '@') = '\0';
50 mrcl_set_message("STRING \"%s\" should be USER or LIST \"%s\" "
51 "because it is a local name.", lname, str);
52 free(lname);
53 return MRCL_REJECT;
54 }
55 free(host);
56 }
57 else if (!strpbrk(str, "%!"))
58 {
59 mrcl_set_message("STRING \"%s\" is not a foreign mail address.\nAdding "
60 "it to a mailing list may cause the list to break.",
b97f7d79 61 str);
74e83a8c 62 return MRCL_WARN;
d5a7ea17 63 }
64
65 mrcl_clear_message();
66 return MRCL_SUCCESS;
67}
68
69int mrcl_validate_kerberos_member(char *str, char **ret)
70{
71 char *p;
72
73 mrcl_clear_message();
74
138b81d7 75 for (p = str; *p; p++)
76 {
77 if (isspace(*p) || *p == ',')
78 {
79 mrcl_set_message("KERBEROS member \"%s\" may not contain whitespace "
80 "or commas.", str);
81 return MRCL_REJECT;
82 }
83 }
84
d5a7ea17 85 p = strchr(str, '@');
86 if (!p)
87 {
88 /* An IP address is not a Kerberos principal, but we allow it
89 * for AFS purposes.
90 */
91 if (strtoul(str, &p, 10) < 256 && (*p == '.') &&
92 strtoul(p + 1, &p, 10) < 256 && (*p == '.') &&
93 strtoul(p + 1, &p, 10) < 256 && (*p == '.') &&
94 strtoul(p + 1, &p, 10) < 256 && !*p)
95 {
96 *ret = strdup(str);
97 return MRCL_SUCCESS;
98 }
99
100 if (!*default_realm)
101 krb_get_lrealm(default_realm, 1);
102
103 *ret = malloc(strlen(str) + strlen(default_realm) + 2);
104 sprintf(*ret, "%s@%s", str, default_realm);
105
106 mrcl_set_message("Warning: default realm \"%s\" added to principal "
107 "\"%s\"", default_realm, str);
108 return MRCL_SUCCESS;
109 }
110
111 /* Check capitalization. */
112 *ret = strdup(str);
113 p = strchr(*ret, '@');
114 while (*++p)
115 {
116 if (islower(*p))
117 {
118 *p = toupper(*p);
119 mrcl_set_message("Warning: set realm in \"%s\" to all caps.", *ret);
120 }
121 }
122
123 return MRCL_SUCCESS;
124}
This page took 0.100489 seconds and 5 git commands to generate.