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.
49 sprintf(buf, "Address: %-10s Box: %-35s Type: %s", info[PO_NAME],
50 info[PO_BOX], info[PO_TYPE]);
52 sprintf(buf, MOD_FORMAT, info[4], info[3], info[5]);
56 /* Function Name: RealPrintPOMachines
57 * Description: Actually does the printing for PrintPOMachines.
58 * Arguments: info, - name of machines in info[1].
63 RealPrintPOMachines(info)
66 Print(1, info + 1, (char *) NULL);
69 /* Function Name: PrintPOMachines
70 * Description: Prints all current post offices.
72 * Returns: SUB_ERROR if the machines could not be printed.
79 static char * args[] = {"pop", NULL};
80 struct qelem * top = NULL;
82 if ( (status = do_mr_query("get_server_locations", CountArgs(args), args,
83 StoreInfo, (char *)&top)) != MR_SUCCESS) {
84 com_err(program_name, status, " in get_server_locations.");
89 Loop(top, RealPrintPOMachines);
94 /* Function Name: GetUserPOBox
95 * Description: prints the users POBox information.
96 * Arguments: argc, argv - name of the user in argv[1].
102 GetUserPOBox(argc, argv)
107 struct qelem * top = NULL;
110 if (!ValidName(argv[1]))
113 switch (status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo,
116 Put_message("This user has no P.O. Box.");
119 sprintf(buf,"Current pobox for user %s: \n", argv[1]);
122 Loop(top, PrintPOBox); /* should only return 1 box. */
126 com_err(program_name, status, " in get_pobox.");
131 /* Function Name: GetNewLocalPOBox
132 * Description: get the machine for a new local pop Box for the user.
133 * Arguments: local_user - name of the local user.
134 * Returns: machine - name of the machine for then new pop box, or NULL.
138 GetNewLocalPOBox(local_user)
141 char temp_buf[BUFSIZ];
143 sprintf(temp_buf,"%s %s", "Pick one of the following",
144 "machines for this user's Post Office.");
145 Put_message(temp_buf);
147 if (PrintPOMachines() == SUB_NORMAL) {
149 if (!Prompt_input("Which Machine? ", temp_buf, BUFSIZ))
150 return((char *) SUB_ERROR);
151 return(canonicalize_hostname(strsave(temp_buf)));
153 Put_message("Could not get machines to choose from, quitting.");
154 return((char *) SUB_ERROR);
157 /* Function Name: SetUserPOBox
158 * Description: Addes or Chnages the P.O. Box for a user.
159 * Arguments: argc, argv - the login name of the user in argv[1].
160 * Returns: DM_NORMAL.
164 SetUserPOBox(argc, argv)
169 char *type, temp_buf[BUFSIZ], *local_user, *args[10], box[BUFSIZ];
171 struct qelem * top = NULL;
172 local_user = argv[1];
174 if (!ValidName(local_user))
177 /* Print the current PO Box info */
178 switch (status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo,
181 sprintf(temp_buf,"Current pobox for user %s: \n", local_user);
184 Loop(top, PrintPOBox); /* should only return 1 box. */
188 Put_message("This user has no P.O. Box.");
191 com_err(program_name, status, " in get_pobox.");
195 sprintf(temp_buf, "Assign %s a local PO Box (y/n)", local_user);
196 switch (YesNoQuestion(temp_buf, TRUE)) {
199 switch (YesNoQuestion("Use Previous Local Box (y/n)", TRUE)) {
201 switch (status = do_mr_query("set_pobox_pop", 1,
202 &local_user, Scream, NULL)) {
206 sprintf(temp_buf, "%s did not have a previous local PO Box.",
208 Put_message(temp_buf);
209 if ( (temp_box = GetNewLocalPOBox(local_user)) !=
210 (char *) SUB_ERROR) {
211 strcpy(box, temp_box);
218 com_err(program_name, status, " in set_pobox_pop.");
223 if ( (temp_box = GetNewLocalPOBox(local_user)) !=
224 (char *) SUB_ERROR) {
225 strcpy(box, temp_box);
237 sprintf(temp_buf, "Set up a foreign PO Box for %s (y/n)", local_user);
238 switch( YesNoQuestion(temp_buf, TRUE)) {
240 if (!Prompt_input("Foreign PO Box for this user? ", box, BUFSIZ))
245 return(DM_NORMAL); /* ^C hit. */
248 default: /* ^C hit. */
249 Put_message("Aborted.");
253 args[PO_NAME] = local_user;
254 args[PO_TYPE] = type;
257 if ( (status = do_mr_query("set_pobox", CountArgs(args), args,
258 Scream, NULL)) != MR_SUCCESS )
259 com_err(program_name, status, " in ChangeUserPOBox");
261 Put_message("PO Box assigned.");
266 /* Function Name: RemoveUserPOBox
267 * Description: Removes this users POBox.
268 * Arguments: argc, argv - name of user in argv[1].
269 * Returns: DM_NORMAL.
274 RemoveUserPOBox(argc, argv)
279 char temp_buf[BUFSIZ];
281 if (!ValidName(argv[1]))
285 "Are you sure that you want to remove %s's PO Box (y/n)", argv[1]);
287 if (Confirm(temp_buf)) {
288 if ( (status = do_mr_query("delete_pobox", 1, argv + 1,
289 Scream, NULL)) != MR_SUCCESS)
290 com_err(program_name, status, " in delete_pobox.");
292 Put_message("PO Box removed.");