]> andersk Git - moira.git/blame - clients/chpobox/chpobox.c
Add support for get_host_by_account_number query.
[moira.git] / clients / chpobox / chpobox.c
CommitLineData
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
39RCSID("$Header$");
40
41int get_pobox(int argc, char **argv, void *callarg);
42void usage(void);
43
44char *whoami;
45
46static int match;
47
48int 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;
2ece76ba 110 status = mrcl_validate_pobox_smtp(uname, address, &addr);
111 if (mrcl_get_message())
112 mrcl_com_err(whoami);
113 if (status != MRCL_SUCCESS)
4a068fb9 114 {
115 printf("\n");
116 goto show;
117 }
118 mrarg[1] = setflag ? "SMTP" : "SPLIT";
119 mrarg[2] = addr;
120 status = mr_query("set_pobox", 3, mrarg, NULL, NULL);
121 free(addr);
122 if (status)
123 {
124 com_err(whoami, status,
125 "while setting pobox for %s to type %s, box %s",
126 mrarg[0], mrarg[1], mrarg[2]);
127 }
128 }
129 else if (prevflag)
130 {
131 status = mr_query("set_pobox_pop", 1, mrarg, NULL, NULL);
132 if (status == MR_MACHINE)
133 {
134 fprintf(stderr,
135 "Moira has no record of a previous POP box for %s\n", uname);
136 }
137 else if (status != 0)
138 com_err(whoami, status, "while setting pobox");
139 }
140
141 /*
142 * get current box
143 */
144show:
145 status = mr_query("get_pobox", 1, mrarg, get_pobox, NULL);
146 if (status == MR_NO_MATCH)
147 printf("User %s has no pobox.\n", uname);
148 else if (status != 0)
3b5b0aeb 149 mrcl_com_err(whoami);
4a068fb9 150 mr_disconnect();
151 exit(0);
152}
153
154
155/*
156 * get_pobox gets all your poboxes and displays them.
157 */
158
159int get_pobox(int argc, char **argv, void *callarg)
160{
161 if (!strcmp(argv[1], "SMTP"))
162 {
163 printf("User %s, Type %s, Box: %s\n",
164 argv[0], argv[1], argv[2]);
165 }
166 else if (argc == 7)
167 {
168 printf("User %s, Type %s, Box: %s (%s)\n",
169 argv[0], argv[1], argv[2], argv[3]);
170 }
171 else
172 {
173 printf("User %s, Type %s, Box: %s@%s\n",
174 argv[0], argv[1], argv[0], argv[2]);
175 }
176 printf(" Modified by %s on %s with %s\n",
177 argv[argc - 2], argv[argc - 3], argv[argc - 1]);
178 return 0;
179}
180
181void usage(void)
182{
94989e92 183 fprintf(stderr, "Usage: %s [-s|-S address] [-p] [-u user]\n", whoami);
4a068fb9 184 exit(1);
185}
This page took 0.16943 seconds and 5 git commands to generate.