]> andersk Git - moira.git/blame - clients/passwd/chpobox.c
Fix uninitialized queue element pointer in CreateImapBox().
[moira.git] / clients / passwd / chpobox.c
CommitLineData
c441a31a 1/* $Id$
48fbc492 2 *
59ec8dae 3 * Talk to the Moira database to change a person's home mail machine. This may
48fbc492 4 * be an Athena machine, or a completely arbitrary address.
5eaef520 5 *
8c5c4d26 6 * chpobox with no modifiers reports the current mailbox.
5eaef520 7 *
979b5f38 8 * chpobox -s address means set the mailbox to this address.
48fbc492 9 *
979b5f38 10 * chpobox -p restores the pobox to a previous POP/IMAP box, if there was one.
48fbc492 11 *
450849e9 12 * chpobox -S address means split mail between POP/IMAP and SMTP
13 *
67655a21 14 * chpobox -u [user] is needed if you are logged in as one user, but
48fbc492 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.
7ac48069 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>.
48fbc492 22 */
23
7ac48069 24#include <mit-copyright.h>
25#include <moira.h>
26#include <moira_site.h>
756eb5df 27#include <mrclient.h>
7ac48069 28
48fbc492 29#include <pwd.h>
7ac48069 30#include <stdio.h>
31#include <stdlib.h>
f071d8a7 32#include <string.h>
7ac48069 33#include <unistd.h>
48fbc492 34
7ac48069 35RCSID("$Header$");
48fbc492 36
7ac48069 37int get_pobox(int argc, char **argv, void *callarg);
3f738519 38void usage(void);
48fbc492 39
7ac48069 40char *whoami;
48fbc492 41
48fbc492 42static int match;
43
5eaef520 44int main(int argc, char *argv[])
48fbc492 45{
5eaef520 46 struct passwd *pwd;
756eb5df 47 char *mrarg[3];
48 char *address, *uname;
450849e9 49 int c, setflag, splitflag, prevflag, status;
5eaef520 50
450849e9 51 setflag = splitflag = prevflag = 0;
7ac48069 52 address = uname = NULL;
5eaef520 53
54 if ((whoami = strrchr(argv[0], '/')) == NULL)
55 whoami = argv[0];
56 else
57 whoami++;
58
59 if (argc > 5)
60 usage();
61
450849e9 62 while ((c = getopt(argc, argv, "s:S:pu:")) != -1)
5eaef520 63 switch (c)
64 {
65 case 's':
450849e9 66 setflag++;
67 address = optarg;
68 break;
69
70 case 'S':
71 splitflag++;
72 address = optarg;
5eaef520 73 break;
450849e9 74
5eaef520 75 case 'p':
450849e9 76 prevflag++;
5eaef520 77 break;
450849e9 78
5eaef520 79 case 'u':
756eb5df 80 uname = optarg;
5eaef520 81 break;
450849e9 82
5eaef520 83 default:
756eb5df 84 usage();
5eaef520 85 break;
86 }
87 if (argc == 2 && optind == 1 && !uname)
88 uname = argv[optind++];
89
450849e9 90 if (optind != argc || (prevflag + splitflag + setflag > 1))
5eaef520 91 usage();
92
93 if (!uname)
94 {
756eb5df 95 uname = mrcl_krb_user();
96 if (!uname)
97 exit(1);
48fbc492 98 }
5eaef520 99 mrarg[0] = uname;
48fbc492 100
acde26f0 101 if (mrcl_connect(NULL, "chpobox", 2, 1) != MRCL_SUCCESS)
756eb5df 102 exit(1);
ccd5efe6 103
450849e9 104 if (setflag || splitflag)
5eaef520 105 {
756eb5df 106 char *addr;
107 if (mrcl_validate_pobox_smtp(uname, address, &addr) != MRCL_SUCCESS)
5eaef520 108 {
756eb5df 109 printf("\n");
5eaef520 110 goto show;
8c5c4d26 111 }
450849e9 112 mrarg[1] = setflag ? "SMTP" : "SPLIT";
756eb5df 113 mrarg[2] = addr;
7ac48069 114 status = mr_query("set_pobox", 3, mrarg, NULL, NULL);
756eb5df 115 free(addr);
5eaef520 116 if (status)
756eb5df 117 {
118 com_err(whoami, status,
119 "while setting pobox for %s to type %s, box %s",
120 mrarg[0], mrarg[1], mrarg[2]);
121 }
5eaef520 122 }
450849e9 123 else if (prevflag)
5eaef520 124 {
7ac48069 125 status = mr_query("set_pobox_pop", 1, mrarg, NULL, NULL);
5eaef520 126 if (status == MR_MACHINE)
127 {
128 fprintf(stderr,
129 "Moira has no record of a previous POP box for %s\n", uname);
130 }
131 else if (status != 0)
50762ef9 132 com_err(whoami, status, "while setting pobox");
48fbc492 133 }
ccd5efe6 134
5eaef520 135 /*
136 * get current box
137 */
8c5c4d26 138show:
5eaef520 139 status = mr_query("get_pobox", 1, mrarg, get_pobox, NULL);
140 if (status == MR_NO_MATCH)
141 printf("User %s has no pobox.\n", uname);
142 else if (status != 0)
50762ef9 143 com_err(whoami, status, "while retrieving current mailbox");
5eaef520 144 mr_disconnect();
145 exit(0);
48fbc492 146}
147
8c5c4d26 148
48fbc492 149/*
dbe34e72 150 * get_pobox gets all your poboxes and displays them.
48fbc492 151 */
152
7ac48069 153int get_pobox(int argc, char **argv, void *callarg)
48fbc492 154{
979b5f38 155 if (!strcmp(argv[1], "SMTP"))
156 {
157 printf("User %s, Type %s, Box: %s\n",
158 argv[0], argv[1], argv[2]);
159 }
160 else if (argc == 7)
161 {
162 printf("User %s, Type %s, Box: %s (%s)\n",
163 argv[0], argv[1], argv[2], argv[3]);
164 }
5eaef520 165 else
979b5f38 166 {
167 printf("User %s, Type %s, Box: %s@%s\n",
168 argv[0], argv[1], argv[0], argv[2]);
169 }
170 printf(" Modified by %s on %s with %s\n",
171 argv[argc - 2], argv[argc - 3], argv[argc - 1]);
5eaef520 172 return 0;
48fbc492 173}
174
3f738519 175void usage(void)
48fbc492 176{
5eaef520 177 fprintf(stderr, "Usage: %s [-s address] [-p] [-u user]\n", whoami);
178 exit(1);
48fbc492 179}
This page took 0.124599 seconds and 5 git commands to generate.