]> andersk Git - moira.git/blame - clients/moira/pobox.c
add acl and tag support, fix up zephyr support
[moira.git] / clients / moira / pobox.c
CommitLineData
c441a31a 1/* $Id$
7ac48069 2 *
3 * This is the file pobox.c for the Moira Client, which allows users
59ec8dae 4 * to quickly and easily maintain most parts of the Moira database.
0a2c64cb 5 * It Contains: Functions for handling the poboxes.
5eaef520 6 *
0a2c64cb 7 * Created: 7/10/88
8 * By: Chris D. Peterson
73c83e3d 9 *
7ac48069 10 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
11 * For copying and distribution information, please see the file
12 * <mit-copyright.h>.
73c83e3d 13 */
14
7ac48069 15#include <mit-copyright.h>
8defc06b 16#include <moira.h>
17#include <moira_site.h>
1bf73297 18#include <mrclient.h>
0a2c64cb 19#include "defs.h"
20#include "f_defs.h"
73c83e3d 21#include "globals.h"
73c83e3d 22
7ac48069 23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26
27RCSID("$Header$");
28
73c83e3d 29#define FOREIGN_BOX ("SMTP")
30#define LOCAL_BOX ("POP")
31
32/* Function Name: PrintPOBox
33 * Description: Yet another specialized print function.
34 * Arguments: info - all info about this PO_box.
8defc06b 35 * Returns: MR_CONT
73c83e3d 36 */
37
5eaef520 38static void PrintPOBox(char **info)
73c83e3d 39{
5eaef520 40 char buf[BUFSIZ];
41
979b5f38 42 sprintf(buf, "User: %-10s Box: %-35s Type: %s", info[PO_NAME],
5eaef520 43 info[PO_BOX], info[PO_TYPE]);
44 Put_message(buf);
979b5f38 45 if (info[6])
46 {
47 sprintf(buf, "Address: %s", info[PO_ADDR]);
48 Put_message(buf);
49 sprintf(buf, MOD_FORMAT, info[5], info[4], info[6]);
50 Put_message(buf);
51 }
52 else
53 {
54 sprintf(buf, MOD_FORMAT, info[4], info[3], info[5]);
55 Put_message(buf);
56 }
73c83e3d 57}
58
59/* Function Name: RealPrintPOMachines
60 * Description: Actually does the printing for PrintPOMachines.
61 * Arguments: info, - name of machines in info[1].
62 * Returns: none.
63 */
64
5eaef520 65static void RealPrintPOMachines(char **info)
73c83e3d 66{
5eaef520 67 Print(1, info + 1, NULL);
73c83e3d 68}
69
70/* Function Name: PrintPOMachines
71 * Description: Prints all current post offices.
72 * Arguments: none.
0a2c64cb 73 * Returns: SUB_ERROR if the machines could not be printed.
73c83e3d 74 */
75
5eaef520 76static int PrintPOMachines(void)
73c83e3d 77{
44d12d58 78 int status;
5eaef520 79 static char *args[] = {"pop", NULL};
600b459e 80 struct mqelem *top = NULL;
5eaef520 81
82 if ((status = do_mr_query("get_server_locations", CountArgs(args), args,
7ac48069 83 StoreInfo, &top)))
5eaef520 84 {
85 com_err(program_name, status, " in get_server_locations.");
86 return SUB_ERROR;
0a2c64cb 87 }
5eaef520 88
89 top = QueueTop(top);
90 Loop(top, RealPrintPOMachines);
91 FreeQueue(top);
92 return SUB_NORMAL;
73c83e3d 93}
94
95/* Function Name: GetUserPOBox
96 * Description: prints the users POBox information.
97 * Arguments: argc, argv - name of the user in argv[1].
98 * Returns: DM_NORMAL.
99 */
100
5eaef520 101int GetUserPOBox(int argc, char **argv)
73c83e3d 102{
44d12d58 103 int status;
600b459e 104 struct mqelem *top = NULL;
5eaef520 105 char buf[BUFSIZ];
106
107 if (!ValidName(argv[1]))
108 return DM_NORMAL;
109
7ac48069 110 switch ((status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo, &top)))
5eaef520 111 {
8defc06b 112 case MR_NO_MATCH:
5eaef520 113 Put_message("This user has no P.O. Box.");
114 break;
8defc06b 115 case MR_SUCCESS:
5eaef520 116 sprintf(buf, "Current pobox for user %s: \n", argv[1]);
117 Put_message("");
118 top = QueueTop(top);
119 Loop(top, PrintPOBox); /* should only return 1 box. */
120 FreeQueue(top);
121 break;
73c83e3d 122 default:
5eaef520 123 com_err(program_name, status, " in get_pobox.");
73c83e3d 124 }
5eaef520 125 return DM_NORMAL;
73c83e3d 126}
127
128/* Function Name: GetNewLocalPOBox
129 * Description: get the machine for a new local pop Box for the user.
130 * Arguments: local_user - name of the local user.
0a2c64cb 131 * Returns: machine - name of the machine for then new pop box, or NULL.
73c83e3d 132 */
133
5eaef520 134static char *GetNewLocalPOBox(char *local_user)
73c83e3d 135{
5eaef520 136 char temp_buf[BUFSIZ];
137
138 sprintf(temp_buf, "%s %s", "Pick one of the following",
139 "machines for this user's Post Office.");
140 Put_message(temp_buf);
141 Put_message("");
142 if (PrintPOMachines() == SUB_NORMAL)
143 {
144 Put_message("");
145 if (!Prompt_input("Which Machine? ", temp_buf, BUFSIZ))
146 return (char *) SUB_ERROR;
7ac48069 147 return canonicalize_hostname(strdup(temp_buf));
0a2c64cb 148 }
5eaef520 149 Put_message("Could not get machines to choose from, quitting.");
150 return (char *) SUB_ERROR;
73c83e3d 151}
152
153/* Function Name: SetUserPOBox
154 * Description: Addes or Chnages the P.O. Box for a user.
155 * Arguments: argc, argv - the login name of the user in argv[1].
156 * Returns: DM_NORMAL.
157 */
158
5eaef520 159int SetUserPOBox(int argc, char **argv)
73c83e3d 160{
44d12d58 161 int status;
1bf73297 162 char *type, temp_buf[BUFSIZ], *local_user, *args[10], *box;
5eaef520 163 char *temp_box;
600b459e 164 struct mqelem *top = NULL;
5eaef520 165 local_user = argv[1];
166
167 if (!ValidName(local_user))
168 return DM_NORMAL;
169
170 /* Print the current PO Box info */
7ac48069 171 switch ((status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo, &top)))
5eaef520 172 {
2f25313c 173 case MR_SUCCESS:
5eaef520 174 sprintf(temp_buf, "Current pobox for user %s: \n", local_user);
175 Put_message("");
176 top = QueueTop(top);
177 Loop(top, PrintPOBox); /* should only return 1 box. */
178 FreeQueue(top);
179 break;
2f25313c 180 case MR_NO_MATCH:
5eaef520 181 Put_message("This user has no P.O. Box.");
182 break;
2f25313c 183 default:
5eaef520 184 com_err(program_name, status, " in get_pobox.");
185 return DM_NORMAL;
2f25313c 186 }
187
5eaef520 188 sprintf(temp_buf, "Assign %s a local PO Box (y/n)", local_user);
189 switch (YesNoQuestion(temp_buf, TRUE))
190 {
73c83e3d 191 case TRUE:
5eaef520 192 type = LOCAL_BOX;
193 switch (YesNoQuestion("Use Previous Local Box (y/n)", TRUE))
194 {
73c83e3d 195 case TRUE:
5eaef520 196 switch ((status = do_mr_query("set_pobox_pop", 1,
7ac48069 197 &local_user, NULL, NULL)))
5eaef520 198 {
8defc06b 199 case MR_SUCCESS:
5eaef520 200 return DM_NORMAL;
8defc06b 201 case MR_MACHINE:
5eaef520 202 sprintf(temp_buf, "%s did not have a previous local PO Box.",
203 local_user);
204 Put_message(temp_buf);
1bf73297 205 if ((box = GetNewLocalPOBox(local_user)) == (char *) SUB_ERROR)
5eaef520 206 return DM_NORMAL;
207 break;
73c83e3d 208 default:
5eaef520 209 com_err(program_name, status, " in set_pobox_pop.");
210 return DM_NORMAL;
73c83e3d 211 }
5eaef520 212 break;
73c83e3d 213 case FALSE:
1bf73297 214 if ((box = GetNewLocalPOBox(local_user)) == (char *) SUB_ERROR)
5eaef520 215 return DM_NORMAL;
216 break;
73c83e3d 217 default:
5eaef520 218 return DM_NORMAL;
73c83e3d 219 }
5eaef520 220 break;
73c83e3d 221 case FALSE:
5eaef520 222 type = FOREIGN_BOX;
223 sprintf(temp_buf, "Set up a foreign PO Box for %s (y/n)", local_user);
224 switch (YesNoQuestion(temp_buf, TRUE))
225 {
73c83e3d 226 case TRUE:
1bf73297 227 if (!Prompt_input("Foreign PO Box for this user? ", temp_buf, BUFSIZ))
228 return DM_NORMAL;
229 if (mrcl_validate_pobox_smtp(local_user, temp_buf, &box) !=
230 MRCL_SUCCESS)
5eaef520 231 return DM_NORMAL;
232 break;
73c83e3d 233 case FALSE:
234 default:
5eaef520 235 return DM_NORMAL; /* ^C hit. */
73c83e3d 236 }
5eaef520 237 break;
73c83e3d 238 default: /* ^C hit. */
5eaef520 239 Put_message("Aborted.");
240 return DM_NORMAL;
73c83e3d 241 }
6f368c99 242
5eaef520 243 args[PO_NAME] = local_user;
244 args[PO_TYPE] = type;
245 args[PO_BOX] = box;
abe26090 246 args[3] = NULL;
5eaef520 247 if ((status = do_mr_query("set_pobox", CountArgs(args), args,
7ac48069 248 NULL, NULL)))
5eaef520 249 com_err(program_name, status, " in ChangeUserPOBox");
250 else
251 Put_message("PO Box assigned.");
1bf73297 252 free(box);
5eaef520 253
254 return DM_NORMAL;
73c83e3d 255}
256
257/* Function Name: RemoveUserPOBox
258 * Description: Removes this users POBox.
259 * Arguments: argc, argv - name of user in argv[1].
260 * Returns: DM_NORMAL.
261 */
262
5eaef520 263int RemoveUserPOBox(int argc, char **argv)
73c83e3d 264{
44d12d58 265 int status;
5eaef520 266 char temp_buf[BUFSIZ];
267
268 if (!ValidName(argv[1]))
269 return DM_NORMAL;
270
271 sprintf(temp_buf, "Are you sure that you want to remove %s's PO Box (y/n)",
272 argv[1]);
273
274 if (Confirm(temp_buf))
275 {
276 if ((status = do_mr_query("delete_pobox", 1, argv + 1,
7ac48069 277 NULL, NULL)))
5eaef520 278 com_err(program_name, status, " in delete_pobox.");
279 else
280 Put_message("PO Box removed.");
73c83e3d 281 }
5eaef520 282 return DM_NORMAL;
73c83e3d 283}
This page took 0.169802 seconds and 5 git commands to generate.