]> andersk Git - moira.git/blame - clients/lib/member.c
Build without krb4 if it's unavailable.
[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
cb974713 20#include <krb5.h>
d5a7ea17 21
22RCSID("$Header$");
23
d5a7ea17 24int mrcl_validate_string_member(char *str)
25{
655a8467 26 char *p, *lname, *ret;
27
28 for (ret = str; *ret; ret++)
29 {
30 if (iscntrl(*ret))
31 {
32 mrcl_set_message("STRING \"%s\" contains control characters, "
33 "which are not allowed.", str);
34 return MRCL_REJECT;
35 }
36 }
d5a7ea17 37
38 p = strchr(str, '@');
39 if (p)
40 {
41 char *host = canonicalize_hostname(strdup(++p));
42
43 if (mailtype(host) != MAILTYPE_SMTP)
44 {
45 free(host);
46 lname = strdup(str);
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);
50 free(lname);
51 return MRCL_REJECT;
52 }
53 free(host);
54 }
55 else if (!strpbrk(str, "%!"))
56 {
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.",
b97f7d79 59 str);
74e83a8c 60 return MRCL_WARN;
d5a7ea17 61 }
62
63 mrcl_clear_message();
64 return MRCL_SUCCESS;
65}
66
67int mrcl_validate_kerberos_member(char *str, char **ret)
68{
69 char *p;
cb974713 70 int code = 0;
71 krb5_context context = NULL;
72 char *default_realm = NULL;
d5a7ea17 73
74 mrcl_clear_message();
75
138b81d7 76 for (p = str; *p; p++)
77 {
78 if (isspace(*p) || *p == ',')
79 {
80 mrcl_set_message("KERBEROS member \"%s\" may not contain whitespace "
81 "or commas.", str);
82 return MRCL_REJECT;
83 }
84 }
85
d5a7ea17 86 p = strchr(str, '@');
87 if (!p)
88 {
89 /* An IP address is not a Kerberos principal, but we allow it
90 * for AFS purposes.
91 */
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)
96 {
97 *ret = strdup(str);
98 return MRCL_SUCCESS;
99 }
100
cb974713 101 code = krb5_init_context(&context);
102 if (!code)
103 goto out;
104
105 code = krb5_get_default_realm(context, &default_realm);
106 if (!code)
107 goto out;
d5a7ea17 108
109 *ret = malloc(strlen(str) + strlen(default_realm) + 2);
110 sprintf(*ret, "%s@%s", str, default_realm);
111
112 mrcl_set_message("Warning: default realm \"%s\" added to principal "
113 "\"%s\"", default_realm, str);
cb974713 114
115 out:
116 if (default_realm)
117 free(default_realm);
118 if (context)
119 krb5_free_context(context);
120 if (!code)
121 return code;
d5a7ea17 122 return MRCL_SUCCESS;
123 }
124
125 /* Check capitalization. */
126 *ret = strdup(str);
127 p = strchr(*ret, '@');
128 while (*++p)
129 {
130 if (islower(*p))
131 {
132 *p = toupper(*p);
133 mrcl_set_message("Warning: set realm in \"%s\" to all caps.", *ret);
134 }
135 }
136
137 return MRCL_SUCCESS;
138}
This page took 0.08438 seconds and 5 git commands to generate.