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];
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(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")) {
165 address = index(machine, '.');
167 address = &machine[strlen(machine)];
168 sprintf(address, ".LOCAL");
170 } else if (smsarg[1]) {
175 status = sms_query("set_pobox", 3, smsarg, scream, NULL);
177 com_err(whoami, status,
178 " while setting pobox for %s to type %s, box %s",
179 smsarg[0], smsarg[1], smsarg[2]);
180 } else if (prevpop) {
181 status = sms_query("set_pobox_pop", 1, smsarg, scream, NULL);
182 if (status == SMS_MACHINE) {
184 "SMS has no record of a previous POP box for %s\n", uname);
185 } else if (status != 0)
186 com_err(whoami, status, " while setting pobox");
193 status = sms_query("get_pobox", 1, smsarg, get_pobox, NULL);
194 if (status == SMS_NO_MATCH)
195 printf("User %s has no pobox.\n", uname);
196 else if (status != 0)
197 com_err(whoami, status, " while retrieving current mailbox");
205 com_err(whoami, 0, "Unexpected return value from SMS -- programmer botch");
211 * get_pobox gets all your poboxes and displays them.
216 get_pobox(argc, argv, callarg)
218 char **argv, *callarg;
220 if (!strcmp(argv[1], "POP"))
221 printf("User %s, Type %s, Box: %s@%s\n",
222 argv[0], argv[1], argv[0], argv[2]);
224 printf("User %s, Type %s, Box: %s\n",
225 argv[0], argv[1], argv[2]);
226 printf(" Modified by %s on %s with %s\n", argv[4], argv[3], argv[5]);
231 * given a canonicalized machine name, ask the SMS server if it is of type
232 * pop, or of type local -- if neither, we assume that it's of type foreign.
239 int check_match(), status;
243 status = sms_query("get_server_locations", 1, service,
244 check_match, machine);
245 if (status && (status != SMS_NO_MATCH)) {
246 com_err(whoami, status, " while reading list of POP servers");
252 service[0] = "LOCAL";
253 status = sms_query("get_server_locations", 1, service,
254 check_match, machine);
255 if (status && (status != SMS_NO_MATCH)) {
256 com_err(whoami, status, " while reading list of LOCAL servers");
267 check_match(argc, argv, callback)
269 char **argv, *callback;
274 if (strcasecmp(argv[1], callback) == 0)
282 fprintf(stderr, "Usage: %s [-s address] [-p] [-u user]\n", whoami);