]>
Commit | Line | Data |
---|---|---|
4a068fb9 | 1 | /* $Id$ |
2 | * | |
3 | * Talk to the Moira database to change a person's home mail machine. This may | |
4 | * be an Athena machine, or a completely arbitrary address. | |
5 | * | |
6 | * chpobox with no modifiers reports the current mailbox. | |
7 | * | |
8 | * chpobox -s address means set the mailbox to this address. | |
9 | * | |
10 | * chpobox -p restores the pobox to a previous POP/IMAP box, if there was one. | |
11 | * | |
12 | * chpobox -S address means split mail between POP/IMAP and SMTP | |
13 | * | |
14 | * chpobox -u [user] is needed if you are logged in as one user, but | |
15 | * are trying to change the email address of another. You must have | |
16 | * Kerberos tickets as the person whose address you are trying to | |
17 | * change, or the attempt will fail. | |
18 | * | |
19 | * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology | |
20 | * For copying and distribution information, please see the file | |
21 | * <mit-copyright.h>. | |
22 | */ | |
23 | ||
24 | #include <mit-copyright.h> | |
25 | #include <moira.h> | |
26 | #include <moira_site.h> | |
27 | #include <mrclient.h> | |
28 | ||
4a068fb9 | 29 | #include <stdio.h> |
30 | #include <stdlib.h> | |
31 | #include <string.h> | |
d91d002e | 32 | #ifdef HAVE_UNISTD_H |
4a068fb9 | 33 | #include <unistd.h> |
d91d002e | 34 | #endif |
35 | #ifdef HAVE_GETOPT_H | |
36 | #include <getopt.h> | |
37 | #endif | |
4a068fb9 | 38 | |
39 | RCSID("$Header$"); | |
40 | ||
41 | int get_pobox(int argc, char **argv, void *callarg); | |
42 | void usage(void); | |
43 | ||
44 | char *whoami; | |
45 | ||
46 | static int match; | |
47 | ||
48 | int main(int argc, char *argv[]) | |
49 | { | |
4a068fb9 | 50 | char *mrarg[3]; |
51 | char *address, *uname; | |
52 | int c, setflag, splitflag, prevflag, status; | |
53 | ||
54 | setflag = splitflag = prevflag = 0; | |
55 | address = uname = NULL; | |
56 | ||
57 | if ((whoami = strrchr(argv[0], '/')) == NULL) | |
58 | whoami = argv[0]; | |
59 | else | |
60 | whoami++; | |
61 | ||
62 | if (argc > 5) | |
63 | usage(); | |
64 | ||
65 | while ((c = getopt(argc, argv, "s:S:pu:")) != -1) | |
66 | switch (c) | |
67 | { | |
68 | case 's': | |
69 | setflag++; | |
70 | address = optarg; | |
71 | break; | |
72 | ||
73 | case 'S': | |
74 | splitflag++; | |
75 | address = optarg; | |
76 | break; | |
77 | ||
78 | case 'p': | |
79 | prevflag++; | |
80 | break; | |
81 | ||
82 | case 'u': | |
83 | uname = optarg; | |
84 | break; | |
85 | ||
86 | default: | |
87 | usage(); | |
88 | break; | |
89 | } | |
90 | if (argc == 2 && optind == 1 && !uname) | |
91 | uname = argv[optind++]; | |
92 | ||
93 | if (optind != argc || (prevflag + splitflag + setflag > 1)) | |
94 | usage(); | |
95 | ||
96 | if (!uname) | |
97 | { | |
98 | uname = mrcl_krb_user(); | |
99 | if (!uname) | |
100 | exit(1); | |
101 | } | |
102 | mrarg[0] = uname; | |
103 | ||
104 | if (mrcl_connect(NULL, "chpobox", 2, 1) != MRCL_SUCCESS) | |
105 | exit(1); | |
106 | ||
107 | if (setflag || splitflag) | |
108 | { | |
109 | char *addr; | |
110 | if (mrcl_validate_pobox_smtp(uname, address, &addr) != MRCL_SUCCESS) | |
111 | { | |
112 | printf("\n"); | |
113 | goto show; | |
114 | } | |
115 | mrarg[1] = setflag ? "SMTP" : "SPLIT"; | |
116 | mrarg[2] = addr; | |
117 | status = mr_query("set_pobox", 3, mrarg, NULL, NULL); | |
118 | free(addr); | |
119 | if (status) | |
120 | { | |
121 | com_err(whoami, status, | |
122 | "while setting pobox for %s to type %s, box %s", | |
123 | mrarg[0], mrarg[1], mrarg[2]); | |
124 | } | |
125 | } | |
126 | else if (prevflag) | |
127 | { | |
128 | status = mr_query("set_pobox_pop", 1, mrarg, NULL, NULL); | |
129 | if (status == MR_MACHINE) | |
130 | { | |
131 | fprintf(stderr, | |
132 | "Moira has no record of a previous POP box for %s\n", uname); | |
133 | } | |
134 | else if (status != 0) | |
135 | com_err(whoami, status, "while setting pobox"); | |
136 | } | |
137 | ||
138 | /* | |
139 | * get current box | |
140 | */ | |
141 | show: | |
142 | status = mr_query("get_pobox", 1, mrarg, get_pobox, NULL); | |
143 | if (status == MR_NO_MATCH) | |
144 | printf("User %s has no pobox.\n", uname); | |
145 | else if (status != 0) | |
146 | com_err(whoami, status, "while retrieving current mailbox"); | |
147 | mr_disconnect(); | |
148 | exit(0); | |
149 | } | |
150 | ||
151 | ||
152 | /* | |
153 | * get_pobox gets all your poboxes and displays them. | |
154 | */ | |
155 | ||
156 | int get_pobox(int argc, char **argv, void *callarg) | |
157 | { | |
158 | if (!strcmp(argv[1], "SMTP")) | |
159 | { | |
160 | printf("User %s, Type %s, Box: %s\n", | |
161 | argv[0], argv[1], argv[2]); | |
162 | } | |
163 | else if (argc == 7) | |
164 | { | |
165 | printf("User %s, Type %s, Box: %s (%s)\n", | |
166 | argv[0], argv[1], argv[2], argv[3]); | |
167 | } | |
168 | else | |
169 | { | |
170 | printf("User %s, Type %s, Box: %s@%s\n", | |
171 | argv[0], argv[1], argv[0], argv[2]); | |
172 | } | |
173 | printf(" Modified by %s on %s with %s\n", | |
174 | argv[argc - 2], argv[argc - 3], argv[argc - 1]); | |
175 | return 0; | |
176 | } | |
177 | ||
178 | void usage(void) | |
179 | { | |
94989e92 | 180 | fprintf(stderr, "Usage: %s [-s|-S address] [-p] [-u user]\n", whoami); |
4a068fb9 | 181 | exit(1); |
182 | } |