3 * This is the file pobox.c for the Moira Client, which allows users
4 * to quickly and easily maintain most parts of the Moira database.
5 * It Contains: Functions for handling the poboxes.
8 * By: Chris D. Peterson
10 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
11 * For copying and distribution information, please see the file
15 #include <mit-copyright.h>
17 #include <moira_site.h>
29 #define FOREIGN_BOX ("SMTP")
30 #define LOCAL_BOX ("POP")
32 /* Function Name: PrintPOBox
33 * Description: Yet another specialized print function.
34 * Arguments: info - all info about this PO_box.
38 static void PrintPOBox(char **info)
42 sprintf(buf, "User: %-10s Box: %-35s Type: %s", info[PO_NAME],
43 info[PO_BOX], info[PO_TYPE]);
47 sprintf(buf, "Address: %s", info[PO_ADDR]);
49 sprintf(buf, MOD_FORMAT, info[5], info[4], info[6]);
54 sprintf(buf, MOD_FORMAT, info[4], info[3], info[5]);
59 /* Function Name: RealPrintPOMachines
60 * Description: Actually does the printing for PrintPOMachines.
61 * Arguments: info, - name of machines in info[1].
65 static void RealPrintPOMachines(char **info)
67 Print(1, info + 1, NULL);
70 /* Function Name: PrintPOMachines
71 * Description: Prints all current post offices.
73 * Returns: SUB_ERROR if the machines could not be printed.
76 static int PrintPOMachines(void)
79 static char *args[] = {"pop", NULL};
80 struct mqelem *top = NULL;
82 if ((status = do_mr_query("get_server_locations", CountArgs(args), args,
85 com_err(program_name, status, " in get_server_locations.");
90 Loop(top, RealPrintPOMachines);
95 /* Function Name: GetUserPOBox
96 * Description: prints the users POBox information.
97 * Arguments: argc, argv - name of the user in argv[1].
101 int GetUserPOBox(int argc, char **argv)
104 struct mqelem *top = NULL;
107 if (!ValidName(argv[1]))
110 switch ((status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo, &top)))
113 Put_message("This user has no P.O. Box.");
116 sprintf(buf, "Current pobox for user %s: \n", argv[1]);
119 Loop(top, PrintPOBox); /* should only return 1 box. */
123 com_err(program_name, status, " in get_pobox.");
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.
131 * Returns: machine - name of the machine for then new pop box, or NULL.
134 static char *GetNewLocalPOBox(char *local_user)
136 char temp_buf[BUFSIZ];
138 sprintf(temp_buf, "%s %s", "Pick one of the following",
139 "machines for this user's Post Office.");
140 Put_message(temp_buf);
142 if (PrintPOMachines() == SUB_NORMAL)
145 if (!Prompt_input("Which Machine? ", temp_buf, BUFSIZ))
146 return (char *) SUB_ERROR;
147 return canonicalize_hostname(strdup(temp_buf));
149 Put_message("Could not get machines to choose from, quitting.");
150 return (char *) SUB_ERROR;
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.
159 int SetUserPOBox(int argc, char **argv)
162 char *type, temp_buf[BUFSIZ], *local_user, *args[10], *box;
164 struct mqelem *top = NULL;
165 local_user = argv[1];
167 if (!ValidName(local_user))
170 /* Print the current PO Box info */
171 switch ((status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo, &top)))
174 sprintf(temp_buf, "Current pobox for user %s: \n", local_user);
177 Loop(top, PrintPOBox); /* should only return 1 box. */
181 Put_message("This user has no P.O. Box.");
184 com_err(program_name, status, " in get_pobox.");
188 sprintf(temp_buf, "Assign %s a local PO Box (y/n)", local_user);
189 switch (YesNoQuestion(temp_buf, TRUE))
193 switch (YesNoQuestion("Use Previous Local Box (y/n)", TRUE))
196 switch ((status = do_mr_query("set_pobox_pop", 1,
197 &local_user, NULL, NULL)))
202 sprintf(temp_buf, "%s did not have a previous local PO Box.",
204 Put_message(temp_buf);
205 if ((box = GetNewLocalPOBox(local_user)) == (char *) SUB_ERROR)
209 com_err(program_name, status, " in set_pobox_pop.");
214 if ((box = GetNewLocalPOBox(local_user)) == (char *) SUB_ERROR)
223 sprintf(temp_buf, "Set up a foreign PO Box for %s (y/n)", local_user);
224 switch (YesNoQuestion(temp_buf, TRUE))
227 if (!Prompt_input("Foreign PO Box for this user? ", temp_buf, BUFSIZ))
229 if (mrcl_validate_pobox_smtp(local_user, temp_buf, &box) !=
235 return DM_NORMAL; /* ^C hit. */
238 default: /* ^C hit. */
239 Put_message("Aborted.");
243 args[PO_NAME] = local_user;
244 args[PO_TYPE] = type;
247 if ((status = do_mr_query("set_pobox", CountArgs(args), args,
249 com_err(program_name, status, " in ChangeUserPOBox");
251 Put_message("PO Box assigned.");
257 /* Function Name: RemoveUserPOBox
258 * Description: Removes this users POBox.
259 * Arguments: argc, argv - name of user in argv[1].
260 * Returns: DM_NORMAL.
263 int RemoveUserPOBox(int argc, char **argv)
266 char temp_buf[BUFSIZ];
268 if (!ValidName(argv[1]))
271 sprintf(temp_buf, "Are you sure that you want to remove %s's PO Box (y/n)",
274 if (Confirm(temp_buf))
276 if ((status = do_mr_query("delete_pobox", 1, argv + 1,
278 com_err(program_name, status, " in delete_pobox.");
280 Put_message("PO Box removed.");