[5081] | 1 | /* |
---|
| 2 | * |
---|
| 3 | * Copyright (C) 1989 by the Massachusetts Institute of Technology |
---|
| 4 | * Developed by the MIT Student Information Processing Board (SIPB). |
---|
| 5 | * For copying information, see the file mit-copyright.h in this release. |
---|
| 6 | * |
---|
| 7 | */ |
---|
| 8 | /* |
---|
| 9 | * |
---|
| 10 | * do_misc.c -- Routines to implement the miscellaneous lisp requests |
---|
| 11 | * |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | #include <stdio.h> |
---|
[5439] | 15 | #include <sys/types.h> |
---|
[5081] | 16 | #include <sys/file.h> |
---|
| 17 | #include <signal.h> |
---|
[5439] | 18 | #include <string.h> |
---|
[5081] | 19 | #include <sys/wait.h> |
---|
| 20 | #include <ctype.h> |
---|
| 21 | #include <sys/time.h> |
---|
| 22 | #include <netdb.h> |
---|
| 23 | #include "edsc.h" |
---|
| 24 | |
---|
| 25 | #define MIN(a,b) ((a)<(b)?(a):(b)) |
---|
| 26 | |
---|
| 27 | extern char *edsc_protocol_version, *edsc_version_string; |
---|
| 28 | |
---|
[12267] | 29 | extern const char *local_realm(); |
---|
[5081] | 30 | |
---|
[12439] | 31 | static int list_it(trn_info2 *t_infp, FILE *f, int long_subjects); |
---|
| 32 | |
---|
| 33 | |
---|
[5081] | 34 | do_gpv(args) |
---|
| 35 | char *args; |
---|
| 36 | { |
---|
| 37 | printf("(%s \"%s\")\n", edsc_protocol_version, edsc_version_string, |
---|
| 38 | edsc_protocol_version); |
---|
| 39 | } |
---|
| 40 | |
---|
[5439] | 41 | int use_vectors; |
---|
| 42 | |
---|
| 43 | typedef struct { |
---|
| 44 | char *val; |
---|
| 45 | int ok; |
---|
| 46 | } gotten_word; |
---|
| 47 | |
---|
| 48 | do_set (args) |
---|
| 49 | char *args; |
---|
| 50 | { |
---|
| 51 | char *varname, *value, *tmp, delim; |
---|
| 52 | |
---|
| 53 | if (get_word (&args, &tmp, " ", &delim) < 0) { |
---|
| 54 | printf ("; Missing variable name\n"); |
---|
| 55 | return; |
---|
| 56 | } |
---|
| 57 | varname = tmp; |
---|
| 58 | if (get_word (&args, &tmp, ")", &delim) < 0) { |
---|
| 59 | printf ("; Missing value\n"); |
---|
| 60 | return; |
---|
| 61 | } |
---|
| 62 | value = tmp; |
---|
| 63 | if (args[2]) { |
---|
| 64 | printf ("; Extra parameters supplied\n"); |
---|
| 65 | return; |
---|
| 66 | } |
---|
| 67 | if (!strcmp (varname, "use_vectors")) |
---|
| 68 | use_vectors = atoi (value); |
---|
| 69 | } |
---|
| 70 | |
---|
[5081] | 71 | do_pacl(args) |
---|
| 72 | char *args; |
---|
| 73 | { |
---|
| 74 | char *cp = args, *mtg_name, delim, *filename; |
---|
| 75 | name_blk nb; |
---|
| 76 | dsc_acl *list; |
---|
| 77 | int code,n; |
---|
| 78 | register dsc_acl_entry *ae; |
---|
| 79 | FILE *f; |
---|
| 80 | |
---|
| 81 | /* First, we get the output filename */ |
---|
| 82 | if (get_word(&cp, &filename, " ", &delim) < 0) { |
---|
| 83 | printf(";Missing filename\n"); |
---|
| 84 | return; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
| 88 | printf(";Missing meeting name\n"); |
---|
| 89 | return; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | (void) chmod(filename, 0600); |
---|
| 93 | if ((f = fopen(filename, "w")) == NULL) { |
---|
| 94 | printf(";%s\n", error_message(errno)); |
---|
| 95 | return; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
| 99 | if (code != 0) { |
---|
| 100 | printf(";%s\n", error_message(code)); |
---|
| 101 | fclose(f); |
---|
| 102 | return; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | dsc_get_acl(&nb, &code, &list); |
---|
| 106 | if (code) { |
---|
| 107 | printf(";Can't read ACL: %s\n", error_message(code)); |
---|
| 108 | fclose(f); |
---|
| 109 | return; |
---|
| 110 | } |
---|
| 111 | for (ae = list->acl_entries, n = list->acl_length; n; --n, ++ae) |
---|
| 112 | fprintf(f, "%-10s %s\n", ae->modes, ae->principal); |
---|
| 113 | acl_destroy(list); |
---|
| 114 | |
---|
| 115 | fclose(f); |
---|
| 116 | dsc_destroy_name_blk(&nb); |
---|
| 117 | printf("()\n"); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | static char edsc_principal_buf[120]; |
---|
| 121 | |
---|
| 122 | char *fix_principal(principal) |
---|
| 123 | char *principal; |
---|
| 124 | { |
---|
| 125 | strcpy(edsc_principal_buf, principal); |
---|
| 126 | if (strcmp(edsc_principal_buf,"*") != 0 && |
---|
[7179] | 127 | strchr(edsc_principal_buf, '@') == 0) { |
---|
[5081] | 128 | strcat(edsc_principal_buf, "@"); |
---|
| 129 | strcat(edsc_principal_buf, local_realm()); |
---|
| 130 | } |
---|
| 131 | return(edsc_principal_buf); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | do_dacl(args) |
---|
| 135 | char *args; |
---|
| 136 | { |
---|
| 137 | char *cp = args, *mtg_name, delim, *principal; |
---|
| 138 | name_blk nb; |
---|
| 139 | int code; |
---|
| 140 | |
---|
| 141 | if (get_word(&cp, &principal, " ", &delim) < 0) { |
---|
| 142 | printf(";Missing principal\n"); |
---|
| 143 | return; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
| 147 | printf(";Missing meeting name\n"); |
---|
| 148 | return; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
| 152 | if (code != 0) { |
---|
| 153 | printf(";%s\n", error_message(code)); |
---|
| 154 | return; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | dsc_delete_access(&nb, fix_principal(principal), &code); |
---|
| 158 | dsc_destroy_name_blk(&nb); |
---|
| 159 | if (code != 0) { |
---|
| 160 | printf(";%s\n", error_message(code)); |
---|
| 161 | return; |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | printf("()\n"); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | do_sacl(args) |
---|
| 168 | char *args; |
---|
| 169 | { |
---|
| 170 | char *cp = args, *mtg_name, delim, *principal, *modes; |
---|
| 171 | register char *p; |
---|
| 172 | name_blk nb; |
---|
| 173 | int code; |
---|
| 174 | |
---|
| 175 | /* First, we get the mode bits */ |
---|
| 176 | if (get_word(&cp, &modes, " ", &delim) < 0) { |
---|
| 177 | printf(";Missing ACL modes\n"); |
---|
| 178 | return; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | if (modes[0] && (modes[0] == '\"') && |
---|
| 182 | (modes[strlen(modes)-1] == '\"')) { |
---|
| 183 | for (p=modes+1; *(p+1); p++) |
---|
| 184 | *(p-1) = *p; |
---|
| 185 | *(p-1) = '\0'; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | if (get_word(&cp, &principal, " ", &delim) < 0) { |
---|
| 189 | printf(";Missing principal\n"); |
---|
| 190 | return; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
| 194 | printf(";Missing meeting name\n"); |
---|
| 195 | return; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
| 199 | if (code != 0) { |
---|
| 200 | printf(";%s\n", error_message(code)); |
---|
| 201 | return; |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | dsc_set_access(&nb, fix_principal(principal), modes, &code); |
---|
| 205 | dsc_destroy_name_blk(&nb); |
---|
| 206 | if (code != 0) { |
---|
| 207 | printf(";%s\n", error_message(code)); |
---|
| 208 | return; |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | printf("()\n"); |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | static char buffer[1024]; |
---|
| 215 | |
---|
| 216 | do_ls(args) |
---|
| 217 | char *args; |
---|
| 218 | { |
---|
| 219 | char *cp = args, *mtg_name, delim, *filename; |
---|
| 220 | char *low_string, *high_string, *filter_string; |
---|
| 221 | name_blk nb; |
---|
| 222 | trn_info2 t_info; |
---|
| 223 | mtg_info m_info; |
---|
| 224 | int code, flags; |
---|
| 225 | FILE *f; |
---|
| 226 | trn_nums trn_num, low, high; |
---|
| 227 | int num_printed = 0; |
---|
| 228 | |
---|
| 229 | /* First, we get the output filename */ |
---|
| 230 | if (get_word(&cp, &filename, " ", &delim) < 0) { |
---|
| 231 | printf(";Missing filename\n"); |
---|
| 232 | return; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | if (get_word(&cp, &low_string, " ", &delim) < 0) { |
---|
| 236 | printf(";Missing lower limit\n"); |
---|
| 237 | return; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | if (get_word(&cp, &high_string, " ", &delim) < 0) { |
---|
| 241 | printf(";Missing upper limit\n"); |
---|
| 242 | return; |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | if (get_word(&cp, &filter_string, " ", &delim) < 0) { |
---|
| 246 | printf(";Missing filter flags\n"); |
---|
| 247 | return; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
| 251 | printf(";Missing meeting name\n"); |
---|
| 252 | return; |
---|
| 253 | } |
---|
| 254 | low = atoi(low_string); |
---|
| 255 | high= atoi(high_string); |
---|
| 256 | flags = atoi(filter_string); |
---|
| 257 | |
---|
| 258 | if ((f = fopen(filename, "w")) == NULL) { |
---|
| 259 | printf(";%s\n", error_message(errno)); |
---|
| 260 | return; |
---|
| 261 | } |
---|
| 262 | (void) chmod(filename, 0600); |
---|
| 263 | |
---|
| 264 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
| 265 | if (code != 0) { |
---|
| 266 | printf(";%s\n", error_message(code)); |
---|
| 267 | fclose(f); |
---|
| 268 | return; |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | trn_num = low; |
---|
| 272 | if (flags & flag_AREF) { |
---|
| 273 | dsc_get_trn_info2 (&nb, trn_num, &t_info, &code); |
---|
| 274 | if (code != 0) { |
---|
| 275 | printf(";[%04d]: %s\n", trn_num, error_message(code)); |
---|
| 276 | dsc_destroy_name_blk(&nb); |
---|
| 277 | fclose(f); |
---|
| 278 | return; |
---|
| 279 | } |
---|
| 280 | trn_num = t_info.fref; |
---|
| 281 | dsc_destroy_trn_info(&t_info); |
---|
| 282 | } else { |
---|
| 283 | dsc_get_mtg_info(&nb,&m_info,&code); |
---|
| 284 | if (code != 0) { |
---|
| 285 | printf(";%s\n", error_message(code)); |
---|
| 286 | dsc_destroy_name_blk(&nb); |
---|
| 287 | fclose(f); |
---|
| 288 | return; |
---|
| 289 | } |
---|
| 290 | if (trn_num < m_info.first) |
---|
| 291 | trn_num = m_info.first; |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | while (trn_num) { |
---|
| 295 | dsc_get_trn_info2 (&nb, trn_num, &t_info, &code); |
---|
| 296 | if (code == DELETED_TRN) { |
---|
| 297 | if (!(flags & (filter_INCLUDE_DELETED | |
---|
| 298 | filter_ONLY_DELETED))) { |
---|
| 299 | trn_num++; |
---|
| 300 | dsc_destroy_trn_info(&t_info); |
---|
| 301 | if ((trn_num > high) || (flags & flag_AREF)) |
---|
| 302 | break; |
---|
| 303 | continue; |
---|
| 304 | } |
---|
| 305 | } else if (code) { |
---|
| 306 | printf("-[%04d]: %s\n", trn_num, error_message(code)); |
---|
| 307 | goto loop_end; |
---|
| 308 | } |
---|
| 309 | if (flags & filter_ONLY_DELETED) { |
---|
| 310 | if (!(t_info.flags & TRN_FDELETED)) |
---|
| 311 | goto loop_end; |
---|
| 312 | } else if (!(flags & filter_INCLUDE_DELETED)) |
---|
| 313 | if (t_info.flags & TRN_FDELETED) |
---|
| 314 | goto loop_end; |
---|
| 315 | if (flags & filter_ONLY_INITIAL) |
---|
| 316 | if (t_info.pref) |
---|
| 317 | goto loop_end; |
---|
| 318 | if (flags & filter_ONLY_TERMINAL) |
---|
| 319 | if (t_info.nref) |
---|
| 320 | goto loop_end; |
---|
| 321 | if (flags & filter_FLAG_SET) |
---|
| 322 | if (!(t_info.flags & TRN_FLAG1)) |
---|
| 323 | goto loop_end; |
---|
| 324 | if (flags & filter_FLAG_RESET) |
---|
| 325 | if (t_info.flags & TRN_FLAG1) |
---|
| 326 | goto loop_end; |
---|
[5439] | 327 | list_it(&t_info,f, 1); |
---|
[5081] | 328 | num_printed++; |
---|
| 329 | loop_end: |
---|
| 330 | if (flags & |
---|
| 331 | (filter_INCLUDE_DELETED | filter_ONLY_DELETED)) |
---|
| 332 | trn_num++; |
---|
| 333 | else if (flags & flag_AREF) |
---|
| 334 | trn_num = t_info.nref; |
---|
| 335 | else |
---|
| 336 | trn_num = t_info.next; |
---|
| 337 | if (!(flags & flag_AREF)) |
---|
| 338 | if (trn_num > high) |
---|
| 339 | trn_num = 0; |
---|
| 340 | dsc_destroy_trn_info(&t_info); |
---|
| 341 | } |
---|
| 342 | fclose(f); |
---|
| 343 | dsc_destroy_name_blk(&nb); |
---|
| 344 | printf("(%d)\n", num_printed); |
---|
| 345 | } |
---|
| 346 | |
---|
[12439] | 347 | static int list_it(t_infop, f, long_subjects) |
---|
[5081] | 348 | trn_info2 *t_infop; |
---|
| 349 | FILE *f; |
---|
| 350 | int long_subjects; |
---|
| 351 | { |
---|
| 352 | char newtime[26], nlines[10]; |
---|
| 353 | char *cp; |
---|
[5439] | 354 | int len; |
---|
[5081] | 355 | |
---|
| 356 | strcpy(newtime, short_time(&t_infop->date_entered)); |
---|
| 357 | /* |
---|
| 358 | * If author ends with current realm, punt the realm. |
---|
| 359 | */ |
---|
[7179] | 360 | if ((cp=strchr(t_infop->author, '@')) != NULL) |
---|
[5081] | 361 | if (!strcmp(cp+1, local_realm())) |
---|
| 362 | *cp = '\0'; |
---|
| 363 | |
---|
| 364 | (void) sprintf (nlines, "(%d)", t_infop->num_lines); |
---|
| 365 | (void) sprintf (buffer, " [%04d]%c%c", |
---|
| 366 | t_infop->current, |
---|
| 367 | ((t_infop->flags & TRN_FLAG1) != 0) ? 'F' : ' ', |
---|
| 368 | ((t_infop->flags & TRN_FDELETED) != 0) ? 'D' : ' '); |
---|
[5439] | 369 | if ((len = MIN(5, 13-strlen (buffer)) - strlen (nlines)) > 0) |
---|
| 370 | (void) strncat (buffer, " ", len); |
---|
[5081] | 371 | |
---|
| 372 | if (strlen(t_infop->author) > 15) |
---|
| 373 | (void) strcpy(&t_infop->author[12], "..."); |
---|
| 374 | |
---|
| 375 | (void) sprintf (buffer + strlen (buffer), "%s %s %-15s ", |
---|
| 376 | nlines, newtime, t_infop->author); |
---|
[5439] | 377 | len = 79 - strlen (buffer); |
---|
[5081] | 378 | |
---|
[5439] | 379 | if (!long_subjects && strlen (t_infop->subject) > len) |
---|
| 380 | (void) strcpy (&t_infop->subject [len - 3], "..."); |
---|
[5081] | 381 | |
---|
| 382 | (void) fprintf (f, "%s%s\n", buffer, t_infop->subject); |
---|
| 383 | |
---|
| 384 | } |
---|
| 385 | |
---|