1 #if (!defined(lint) && !defined(SABER))
2 static char rcsid_module_c[] = "$Header$";
5 /* This is the file pobox.c for the MOIRA Client, which allows a nieve
6 * user to quickly and easily maintain most parts of the MOIRA database.
7 * It Contains: Functions for handling the poboxes.
10 * By: Chris D. Peterson
16 * Copyright 1988 by the Massachusetts Institute of Technology.
18 * For further information on copyright and distribution
19 * see the file mit-copyright.h
26 #include <moira_site.h>
29 #include "mit-copyright.h"
34 #define FOREIGN_BOX ("SMTP")
35 #define LOCAL_BOX ("POP")
37 /* Function Name: PrintPOBox
38 * Description: Yet another specialized print function.
39 * Arguments: info - all info about this PO_box.
43 static void PrintPOBox(char **info)
47 sprintf(buf, "Address: %-10s Box: %-35s Type: %s", info[PO_NAME],
48 info[PO_BOX], info[PO_TYPE]);
50 sprintf(buf, MOD_FORMAT, info[4], info[3], info[5]);
54 /* Function Name: RealPrintPOMachines
55 * Description: Actually does the printing for PrintPOMachines.
56 * Arguments: info, - name of machines in info[1].
60 static void RealPrintPOMachines(char **info)
62 Print(1, info + 1, NULL);
65 /* Function Name: PrintPOMachines
66 * Description: Prints all current post offices.
68 * Returns: SUB_ERROR if the machines could not be printed.
71 static int PrintPOMachines(void)
74 static char *args[] = {"pop", NULL};
75 struct qelem *top = NULL;
77 if ((status = do_mr_query("get_server_locations", CountArgs(args), args,
78 StoreInfo, (char *)&top)))
80 com_err(program_name, status, " in get_server_locations.");
85 Loop(top, RealPrintPOMachines);
90 /* Function Name: GetUserPOBox
91 * Description: prints the users POBox information.
92 * Arguments: argc, argv - name of the user in argv[1].
96 int GetUserPOBox(int argc, char **argv)
99 struct qelem *top = NULL;
102 if (!ValidName(argv[1]))
105 switch ((status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo,
109 Put_message("This user has no P.O. Box.");
112 sprintf(buf, "Current pobox for user %s: \n", argv[1]);
115 Loop(top, PrintPOBox); /* should only return 1 box. */
119 com_err(program_name, status, " in get_pobox.");
124 /* Function Name: GetNewLocalPOBox
125 * Description: get the machine for a new local pop Box for the user.
126 * Arguments: local_user - name of the local user.
127 * Returns: machine - name of the machine for then new pop box, or NULL.
130 static char *GetNewLocalPOBox(char *local_user)
132 char temp_buf[BUFSIZ];
134 sprintf(temp_buf, "%s %s", "Pick one of the following",
135 "machines for this user's Post Office.");
136 Put_message(temp_buf);
138 if (PrintPOMachines() == SUB_NORMAL)
141 if (!Prompt_input("Which Machine? ", temp_buf, BUFSIZ))
142 return (char *) SUB_ERROR;
143 return canonicalize_hostname(strsave(temp_buf));
145 Put_message("Could not get machines to choose from, quitting.");
146 return (char *) SUB_ERROR;
149 /* Function Name: SetUserPOBox
150 * Description: Addes or Chnages the P.O. Box for a user.
151 * Arguments: argc, argv - the login name of the user in argv[1].
152 * Returns: DM_NORMAL.
155 int SetUserPOBox(int argc, char **argv)
158 char *type, temp_buf[BUFSIZ], *local_user, *args[10], box[BUFSIZ];
160 struct qelem *top = NULL;
161 local_user = argv[1];
163 if (!ValidName(local_user))
166 /* Print the current PO Box info */
167 switch ((status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo,
171 sprintf(temp_buf, "Current pobox for user %s: \n", local_user);
174 Loop(top, PrintPOBox); /* should only return 1 box. */
178 Put_message("This user has no P.O. Box.");
181 com_err(program_name, status, " in get_pobox.");
185 sprintf(temp_buf, "Assign %s a local PO Box (y/n)", local_user);
186 switch (YesNoQuestion(temp_buf, TRUE))
190 switch (YesNoQuestion("Use Previous Local Box (y/n)", TRUE))
193 switch ((status = do_mr_query("set_pobox_pop", 1,
194 &local_user, Scream, NULL)))
199 sprintf(temp_buf, "%s did not have a previous local PO Box.",
201 Put_message(temp_buf);
202 if ((temp_box = GetNewLocalPOBox(local_user)) !=
205 strcpy(box, temp_box);
212 com_err(program_name, status, " in set_pobox_pop.");
217 if ((temp_box = GetNewLocalPOBox(local_user)) !=
220 strcpy(box, temp_box);
232 sprintf(temp_buf, "Set up a foreign PO Box for %s (y/n)", local_user);
233 switch (YesNoQuestion(temp_buf, TRUE))
236 if (!Prompt_input("Foreign PO Box for this user? ", box, BUFSIZ))
241 return DM_NORMAL; /* ^C hit. */
244 default: /* ^C hit. */
245 Put_message("Aborted.");
249 args[PO_NAME] = local_user;
250 args[PO_TYPE] = type;
253 if ((status = do_mr_query("set_pobox", CountArgs(args), args,
255 com_err(program_name, status, " in ChangeUserPOBox");
257 Put_message("PO Box assigned.");
262 /* Function Name: RemoveUserPOBox
263 * Description: Removes this users POBox.
264 * Arguments: argc, argv - name of user in argv[1].
265 * Returns: DM_NORMAL.
268 int RemoveUserPOBox(int argc, char **argv)
271 char temp_buf[BUFSIZ];
273 if (!ValidName(argv[1]))
276 sprintf(temp_buf, "Are you sure that you want to remove %s's PO Box (y/n)",
279 if (Confirm(temp_buf))
281 if ((status = do_mr_query("delete_pobox", 1, argv + 1,
283 com_err(program_name, status, " in delete_pobox.");
285 Put_message("PO Box removed.");