2 * Copyright 1987 by the Massachusetts Institute of Technology. For copying
3 * and distribution information, see the file "mit-copyright.h".
12 static char *rcsid_chpobox_c = "$Header$";
16 * Talk to the SMS database to change a person's home mail machine. This may
17 * be an Athena machine, or a completely arbitrary address.
19 * chpobox with no modifiers reports the current mailbox.
21 * chpobox -s [address] means set the mailbox to this address.
23 * chpobox -p restores the pobox to a previous POP box, if there was one.
25 * chpobox -u [user] is needed if you are logged in as one user, but
26 * are trying to change the email address of another. You must have
27 * Kerberos tickets as the person whose address you are trying to
28 * change, or the attempt will fail.
31 #include <sys/types.h>
41 #include "mit-copyright.h"
58 char *smsarg[3], buf[BUFSIZ];
59 char *potype(), *index();
60 char *address, *uname, *machine;
62 char *canonicalize_hostname();
63 int get_pobox(), scream();
64 int c, setflag, prevpop, usageflag, status;
69 c = setflag = prevpop = usageflag = 0;
70 address = uname = (char *) NULL;
73 if ((whoami = rindex(argv[0], '/')) == NULL)
82 while ((c = getopt(argc, argv, "s:pu:")) != EOF)
102 uname = strsave(optarg);
108 if (argc == 2 && optind == 1 && !uname) {
109 uname = argv[optind++];
111 if (usageflag || optind != argc) {
115 if ((uname = getlogin()) == NULL) {
118 if (uname[0] == '\0') {
119 pwd = getpwuid((int) u);
120 (void) strcpy(uname, pwd->pw_name);
125 status = sms_connect(SMS_SERVER);
127 com_err(whoami, status, " while connecting to SMS");
131 status = sms_auth("chpobox");
133 com_err(whoami, status, " while authenticating -- run \"kinit\" and try again.");
139 /* Address is of form user@host. Split it up. */
141 fprintf(stderr, "%s: no address was specified.\n", whoami);
144 machine = index(address, '@');
146 *machine++ = '\0'; /* get rid of the @ sign */
147 machine = strtrim(machine); /* get rid of whitespace */
149 fprintf(stderr, "%s: no at sign (@) in address \"%s\"\n",
153 smsarg[2] = canonicalize_hostname(strsave(machine));
154 smsarg[1] = potype(smsarg[2]);
155 if (!strcmp(smsarg[1], "POP")) {
156 if (strcmp(address, uname)) {
158 "%s: the name on the POP box must match the username\n",
162 } else if (!strcmp(smsarg[1], "LOCAL")) {
163 strcat(address, "@");
164 strcat(address, smsarg[2]);
166 if ((address = index(address, '@')) &&
167 (address = index(address, '.')))
169 strcat(smsarg[2], ".LOCAL");
171 } else if (smsarg[1]) {
172 if (*machine != '"' && strcasecmp(smsarg[2], machine))
173 printf("Warning: hostname %s canonicalized to %s\n",
175 strcat(address, "@");
176 strcat(address, smsarg[2]);
180 status = sms_query("set_pobox", 3, smsarg, scream, NULL);
182 com_err(whoami, status,
183 " while setting pobox for %s to type %s, box %s",
184 smsarg[0], smsarg[1], smsarg[2]);
185 } else if (prevpop) {
186 status = sms_query("set_pobox_pop", 1, smsarg, scream, NULL);
187 if (status == SMS_MACHINE) {
189 "SMS has no record of a previous POP box for %s\n", uname);
190 } else if (status != 0)
191 com_err(whoami, status, " while setting pobox");
198 status = sms_query("get_pobox", 1, smsarg, get_pobox, NULL);
199 if (status == SMS_NO_MATCH)
200 printf("User %s has no pobox.\n", uname);
201 else if (status != 0)
202 com_err(whoami, status, " while retrieving current mailbox");
210 com_err(whoami, 0, "Unexpected return value from SMS -- programmer botch");
216 * get_pobox gets all your poboxes and displays them.
221 get_pobox(argc, argv, callarg)
223 char **argv, *callarg;
225 if (!strcmp(argv[1], "POP"))
226 printf("User %s, Type %s, Box: %s@%s\n",
227 argv[0], argv[1], argv[0], argv[2]);
229 printf("User %s, Type %s, Box: %s\n",
230 argv[0], argv[1], argv[2]);
231 printf(" Modified by %s on %s with %s\n", argv[4], argv[3], argv[5]);
236 * given a canonicalized machine name, ask the SMS server if it is of type
237 * pop, or of type local -- if neither, we assume that it's of type foreign.
244 int check_match(), status;
248 status = sms_query("get_server_locations", 1, service,
249 check_match, machine);
250 if (status && (status != SMS_NO_MATCH)) {
251 com_err(whoami, status, " while reading list of POP servers");
257 service[0] = "LOCAL";
258 status = sms_query("get_server_locations", 1, service,
259 check_match, machine);
260 if (status && (status != SMS_NO_MATCH)) {
261 com_err(whoami, status, " while reading list of LOCAL servers");
272 check_match(argc, argv, callback)
274 char **argv, *callback;
279 if (strcasecmp(argv[1], callback) == 0)
287 fprintf(stderr, "Usage: %s [-s address] [-p] [-u user]\n", whoami);