]> andersk Git - moira.git/blob - clients/lib/member.c
break out of case statement, don't fall through.
[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   p = strchr(str, '@');
76   if (!p)
77     {
78       /* An IP address is not a Kerberos principal, but we allow it
79        * for AFS purposes.
80        */
81       if (strtoul(str, &p, 10) < 256 && (*p == '.') &&
82           strtoul(p + 1, &p, 10) < 256 && (*p == '.') &&
83           strtoul(p + 1, &p, 10) < 256 && (*p == '.') &&
84           strtoul(p + 1, &p, 10) < 256 && !*p)
85         {
86           *ret = strdup(str);
87           return MRCL_SUCCESS;
88         }
89
90       if (!*default_realm)
91         krb_get_lrealm(default_realm, 1);
92
93       *ret = malloc(strlen(str) + strlen(default_realm) + 2);
94       sprintf(*ret, "%s@%s", str, default_realm);
95
96       mrcl_set_message("Warning: default realm \"%s\" added to principal "
97                        "\"%s\"", default_realm, str);
98       return MRCL_SUCCESS;
99     }
100
101   /* Check capitalization. */
102   *ret = strdup(str);
103   p = strchr(*ret, '@');
104   while (*++p)
105     {
106       if (islower(*p))
107         {
108           *p = toupper(*p);
109           mrcl_set_message("Warning: set realm in \"%s\" to all caps.", *ret);
110         }
111     }
112
113   return MRCL_SUCCESS;
114 }
This page took 0.100685 seconds and 5 git commands to generate.