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