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