]> andersk Git - moira.git/blob - clients/lib/member.c
b7603b2bbb6658e694aee8d7c5a8e1e6860498ee
[moira.git] / clients / lib / member.c
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>
18 #include <ctype.h>
19
20 #include <krb.h>
21
22 RCSID("$Header$");
23
24 static char default_realm[REALM_SZ];
25
26 int mrcl_validate_string_member(char *str)
27 {
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     }
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.",
61                        str);
62       return MRCL_WARN;
63     }
64
65   mrcl_clear_message();
66   return MRCL_SUCCESS;
67 }
68
69 int mrcl_validate_kerberos_member(char *str, char **ret)
70 {
71   char *p;
72
73   mrcl_clear_message();
74
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
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.0315839999999999 seconds and 3 git commands to generate.