]> andersk Git - moira.git/blob - clients/lib/member.c
use str, not lname.
[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
19 #include <krb.h>
20
21 RCSID("$Header$");
22
23 static char default_realm[REALM_SZ];
24
25 int mrcl_validate_string_member(char *str)
26 {
27   char *p, *lname;
28
29   p = strchr(str, '@');
30   if (p)
31     {
32       char *host = canonicalize_hostname(strdup(++p));
33
34       if (mailtype(host) != MAILTYPE_SMTP)
35         {
36           free(host);
37           lname = strdup(str);
38           *strchr(str, '@') = '\0';
39           mrcl_set_message("STRING \"%s\" should be USER or LIST \"%s\" "
40                            "because it is a local name.", lname, str);
41           free(lname);
42           return MRCL_REJECT;
43         }
44       free(host);
45     }
46   else if (!strpbrk(str, "%!"))
47     {
48       mrcl_set_message("STRING \"%s\" is not a foreign mail address.\nAdding "
49                        "it to a mailing list may cause the list to break.",
50                        str);
51       return MRCL_SUCCESS;
52     }
53
54   mrcl_clear_message();
55   return MRCL_SUCCESS;
56 }
57
58 int mrcl_validate_kerberos_member(char *str, char **ret)
59 {
60   char *p;
61
62   mrcl_clear_message();
63
64   p = strchr(str, '@');
65   if (!p)
66     {
67       /* An IP address is not a Kerberos principal, but we allow it
68        * for AFS purposes.
69        */
70       if (strtoul(str, &p, 10) < 256 && (*p == '.') &&
71           strtoul(p + 1, &p, 10) < 256 && (*p == '.') &&
72           strtoul(p + 1, &p, 10) < 256 && (*p == '.') &&
73           strtoul(p + 1, &p, 10) < 256 && !*p)
74         {
75           *ret = strdup(str);
76           return MRCL_SUCCESS;
77         }
78
79       if (!*default_realm)
80         krb_get_lrealm(default_realm, 1);
81
82       *ret = malloc(strlen(str) + strlen(default_realm) + 2);
83       sprintf(*ret, "%s@%s", str, default_realm);
84
85       mrcl_set_message("Warning: default realm \"%s\" added to principal "
86                        "\"%s\"", default_realm, str);
87       return MRCL_SUCCESS;
88     }
89
90   /* Check capitalization. */
91   *ret = strdup(str);
92   p = strchr(*ret, '@');
93   while (*++p)
94     {
95       if (islower(*p))
96         {
97           *p = toupper(*p);
98           mrcl_set_message("Warning: set realm in \"%s\" to all caps.", *ret);
99         }
100     }
101
102   return MRCL_SUCCESS;
103 }
This page took 0.06322 seconds and 5 git commands to generate.