COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 1 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 1 /******************************************************************** 2 * wilkinson 3 * 3.16VMS 4 * 1995/09/21 10:00 5 * gopher_root1:[gopher.g2.vms2_13.object]compatible.c,v 6 * Exp 7 * 8 * Paul Lindner, University of Minnesota CIS. 9 * 10 * Copyright 1991, 1992 by the Regents of the University of Minnesota 11 * see the file "Copyright" in the distribution for conditions of use. 12 ********************************************************************* 13 * MODULE: compatible.c 14 * Compatibility routines 15 ********************************************************************* 16 * Revision History: 17 * compatible.c,v 18 * Revision 3.16VMS 1995/09/21 10:00 wilkinson 19 * Consolodate VMS/Unix source code for server as well as client 20 * - move syslog() routines here so available to both server and client 21 * 22 * Revision 3.16 1995/02/06 22:14:22 lindner 23 * Remove const 24 * 25 * Revision 3.15 1994/12/15 17:30:16 lindner 26 * A replacement fgetpwent 27 * 28 * Revision 3.14 1994/07/21 22:18:45 lindner 29 * Add putenv() compat code 30 * 31 * Revision 3.13 1994/04/25 03:34:34 lindner 32 * Put back alpha patch (Fote) 33 * 34 * Revision 3.12 1994/04/08 20:05:55 lindner 35 * gcc -Wall fixes 36 * 37 * Revision 3.11 1994/04/01 04:44:28 lindner 38 * Fix for alpha VMS 39 * 40 * Revision 3.10 1994/03/30 21:38:39 lindner 41 * Remove some VMS code 42 * 43 * Revision 3.9 1994/03/17 04:38:45 lindner 44 * VMS weird directory routines 45 * 46 * Revision 3.8 1994/03/08 03:24:09 lindner 47 * Waitpid for vms 48 * 49 * Revision 3.7 1993/10/27 18:51:10 lindner 50 * Updates for VMS files/records 51 * 52 * Revision 3.6 1993/09/03 03:26:39 lindner 53 * Better VMS tempnam() implementation 54 * 55 * Revision 3.5 1993/06/22 05:53:17 lindner COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 2 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 56 * Added getdtablesize() option 57 * 58 * Revision 3.4 1993/04/15 21:36:30 lindner 59 * Emulation of geteuid calls for HPs 60 * 61 * Revision 3.3 1993/03/18 22:27:46 lindner 62 * better portable tempnam() 63 * 64 * Revision 3.2 1993/02/19 21:33:27 lindner 65 * Gopher1.2b2 release 66 * 67 * Revision 3.1.1.1 1993/02/11 18:03:05 lindner 68 * Gopher+1.2beta release 69 * 70 * Revision 1.4 1993/01/17 03:46:12 lindner 71 * Fixed tempnam for VMS 72 * 73 * Revision 1.3 1993/01/08 23:13:55 lindner 74 * Added more VMS mods from jqj 75 * 76 * 77 *********************************************************************/ 78 79 80 /* 81 * Some functions that aren't implemented on every machine on the net 82 * 83 * definitions should be in the form "NO_FNNAME" 84 * compatible.h looks at preprocessor symbols and automatically defines 85 * many of the NO_FNNAME options 86 * 87 */ 88 89 #include 971 #include 1220 #include "Malloc.h" /*** For NULL ***/ 1878 #include "compatible.h" 2261 2262 /*** For machines that don't have strstr ***/ 2263 2264 #if defined(NOSTRSTR) 2265 X 2266 X char * 2267 X strstr(host_name, cp) 2268 X char *host_name; 2269 X char *cp; 2270 X { 2271 X int i, j; 2272 X 2273 X for (i = 0; i < strlen(host_name); i++) { 2274 X j = strncmp(host_name+i, cp, strlen(cp)); 2275 X if (j == 0) 2276 X return(host_name+i); 2277 X } 2278 X return(NULL); 2279 X } 2280 #endif COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 3 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 2281 2282 #if defined(sequent) 2283 X 2284 X #include 2285 X vsprintf(va_alist) 2286 X va_dcl 2287 X { 2288 X ; 2289 X } 2290 X 2291 X vfprintf(va_alist) 2292 X va_dcl 2293 X { 2294 X ; 2295 X } 2296 X 2297 X 2298 #endif 2299 2300 #if defined(NO_TEMPNAM) 2301 /* A tip of the hat to the developers of elm 2.4pl17, from whence 2302 the non-VMS portion of this routine comes. 2303 */ 2304 /* and a tempnam for temporary files */ 2305 static int cnt = 0; 2306 2307 char *tempnam(dir, pfx) 2308 char *dir; 2309 char *pfx; 2310 { 2311 1 char space[512]; 2312 1 char *newspace; 2313 1 2314 1 #ifdef VMS 2315 1 if (dir == NULL) { 2316 2 dir = "sys$scratch:"; 2317 2 } else if (*dir == '\0') { 2318 2 dir = "sys$scratch:"; 2319 2 } 2320 1 2321 1 if (pfx == NULL) { 2322 2 pfx = "gopher.$"; 2323 2 } else if (*pfx == '\0') { 2324 2 pfx = "gopher.$"; 2325 2 } 2326 1 2327 1 sprintf(space, "%s%s%d%d", dir, pfx, getpid(), cnt); 2328 1 #else 2329 X if (dir == NULL) { 2330 X dir = "/usr/tmp"; 2331 X } else if (*dir == '\0') { 2332 X dir = "/usr/tmp"; 2333 X } 2334 X 2335 X if (pfx == NULL) { 2336 X pfx = ""; 2337 X } COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 4 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 2338 X 2339 X sprintf(space, "%s/%s%d.%d", dir, pfx, getpid(), cnt); 2340 1 #endif 2341 1 cnt++; 2342 1 2343 1 newspace = (char *)malloc(strlen(space) + 1); 2344 1 if (newspace != NULL) { 2345 2 strcpy(newspace, space); 2346 2 } 2347 1 return newspace; 2348 1 } 2349 #endif 2350 2351 #if defined(NO_STRDUP) 2352 char *strdup(str) 2353 char *str; 2354 { 2355 1 int len; 2356 1 char *temp; 2357 1 2358 1 if (str == NULL) return(NULL); 2359 1 len = strlen(str); 2360 1 2361 1 temp = (char *) malloc(sizeof(char) * len + 1); 2362 1 2363 1 strcpy(temp, str); 2364 1 return(temp); 2365 1 } 2366 #endif 2367 2368 #if defined(NO_TZSET) 2369 X void 2370 X tzset() 2371 X { 2372 X ; 2373 X } 2374 #endif 2375 2376 #if defined(NO_STRCASECMP) 2377 /* 2378 * Copyright (c) 1987 Regents of the University of California. 2379 * All rights reserved. 2380 * 2381 * Redistribution and use in source and binary forms, with or without 2382 * modification, are permitted provided that the following conditions 2383 * are met: 2384 * 1. Redistributions of source code must retain the above copyright 2385 * notice, this list of conditions and the following disclaimer. 2386 * 2. Redistributions in binary form must reproduce the above copyright 2387 * notice, this list of conditions and the following disclaimer in the 2388 * documentation and/or other materials provided with the distribution. 2389 * 3. All advertising materials mentioning features or use of this software 2390 * must display the following acknowledgement: 2391 * This product includes software developed by the University of 2392 * California, Berkeley and its contributors. 2393 * 4. Neither the name of the University nor the names of its contributors 2394 * may be used to endorse or promote products derived from this software COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 5 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 2395 * without specific prior written permission. 2396 * 2397 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2398 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2399 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2400 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2401 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2402 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2403 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2404 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2405 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2406 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2407 * SUCH DAMAGE. 2408 * 2409 * Modified for use on VMS by Earl Fogel, University of Saskatchewan 2410 * Computing Services, January 1992 2411 */ 2412 2413 typedef unsigned char U_char; 2414 2415 /* 2416 * This array is designed for mapping upper and lower case letter 2417 * together for a case independent comparison. The mappings are 2418 * based upon ascii character sequences. 2419 */ 2420 static U_char charmap[] = { 2421 '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', 2422 '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', 2423 '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', 2424 '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', 2425 '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', 2426 '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', 2427 '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', 2428 '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', 2429 '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 2430 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 2431 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 2432 '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', 2433 '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', 2434 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', 2435 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', 2436 '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', 2437 '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', 2438 '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', 2439 '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', 2440 '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', 2441 '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', 2442 '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', 2443 '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', 2444 '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', 2445 '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307', 2446 '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317', 2447 '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327', 2448 '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337', 2449 '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 2450 '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 2451 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 6 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 2452 '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', 2453 }; 2454 2455 int 2456 strcasecmp(s1, s2) 2457 const char *s1, *s2; 2458 { 2459 1 register const U_char *cm = charmap, 2460 1 *us1 = (const U_char *)s1, 2461 1 *us2 = (const U_char *)s2; 2462 1 2463 1 while (cm[*us1] == cm[*us2++]) 2464 1 if (*us1++ == '\0') 2465 1 return (0); 2466 1 return (cm[*us1] - cm[*--us2]); 2467 1 } 2468 2469 int 2470 strncasecmp(s1, s2, n) 2471 const char *s1, *s2; 2472 register size_t n; 2473 { 2474 1 if (n != 0) { 2475 2 register const U_char *cm = charmap, 2476 2 *us1 = (const U_char *)s1, 2477 2 *us2 = (const U_char *)s2; 2478 2 2479 2 do { 2480 3 if (cm[*us1] != cm[*us2++]) 2481 3 return (cm[*us1] - cm[*--us2]); 2482 3 if (*us1++ == '\0') 2483 3 break; 2484 3 } while (--n != 0); 2485 2 } 2486 1 return (0); 2487 1 } 2488 2489 #endif 2490 2491 #if defined(NO_GETDTABLESIZE) 2492 X int getdtablesize() 2493 X { 2494 X struct rlimit rlp; 2495 X 2496 X rlp.rlim_cur = rlp.rlim_max = RLIM_INFINITY; 2497 X 2498 X if (getrlimit( RLIMIT_NOFILE, &rlp ) ) 2499 X return(-1); 2500 X fds = rlp.rlim_cur; 2501 X } 2502 #endif 2503 2504 #if defined(VMS) 2505 /* In all versions of VMS, fopen() and open() are needlessly inefficient. 2506 * Define jacket routines to do file opens with more sensible parameters 2507 * than the VAXCRTL default. 2508 * [Should we really be doing this for EVERY fopen() and open()?] COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 7 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 2509 */ 2510 #ifdef fopen 2511 #undef fopen 2512 #endif 2513 #ifdef open 2514 #undef open 2515 #endif 2516 2517 FILE *fopen_VAR ( name, mode ) 2518 char *name, *mode; 2519 { 2520 1 return fopen ( name, mode, "rfm=var","rat=cr","mbc=32" ); 2521 1 } 2522 2523 FILE *fopen_FIX ( name, mode ) 2524 char *name, *mode; 2525 { 2526 1 return fopen ( name, mode, "rfm=fix","mrs=512","mbc=32" ); 2527 1 } 2528 2529 #ifdef VMS_SERVER 2530 X 2531 X int vaxc$errno_stv; 2532 X #include 2533 X #include 2534 X 2535 X FILE *fopen_VMSopt ( name, mode , alq, deq) 2536 X char *name, *mode, *alq, *deq; 2537 X { 2538 X struct FAB fab; 2539 X int status; 2540 X FILE *opened; 2541 X 2542 X errno = vaxc$errno = vaxc$errno_stv = 0; 2543 X if (strcmp(mode,"a")==0) 2544 X opened = fopen (name, mode, "mbc=32", alq, deq); 2545 X else 2546 X opened = fopen ( name, mode, "mbc=32" ); 2547 X if (opened==NULL) { 2548 X fab = cc$rms_fab; 2549 X fab.fab$l_fna = name; 2550 X fab.fab$b_fns = strlen(fab.fab$l_fna); 2551 X if (((status = SYS$OPEN(&fab, 0, 0)) &1) != 1) { 2552 X vaxc$errno = fab.fab$l_sts; 2553 X vaxc$errno_stv = fab.fab$l_stv; 2554 X } 2555 X else SYS$CLOSE(&fab,0,0); 2556 X } 2557 X return opened; 2558 X } 2559 #else 2560 FILE *fopen_VMSopt ( name, mode ) 2561 char *name, *mode; 2562 { 2563 1 return fopen ( name, mode, "mbc=32" ); 2564 1 } 2565 #endif COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 8 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 2566 2567 int open_VMSopt ( name, flags, mode ) 2568 char *name; 2569 int flags; 2570 unsigned int mode; 2571 { 2572 1 return open ( name, flags, mode, "mbc=32"); 2573 1 } 2574 2575 #endif 2576 2577 #if defined(VMS_SERVER) && !defined(MULTINET) 2578 X 2579 X /* Multinet defines a handy vms_errno_string() that essentially packages 2580 X * strerror with no parameters. (This insulates other platforms from 2581 X * VMS' oddball two-argument strerror.) We need to supply it here for 2582 X * other IP packages under VMS. 2583 X */ 2584 X 2585 X char *vms_errno_string (void) { return(strerror(errno, vaxc$errno)); } 2586 X 2587 #endif 2588 2589 2590 #if defined(VMS) || defined(NO_WAITPID_WAIT3) 2591 # include "Wait.h" 2764 2765 pid_t waitpid(pid, status, options) 2766 pid_t pid; 2767 int *status; 2768 int options; 2769 { 2770 1 int zepid; 2771 1 2772 1 while ((zepid = wait(status)) != pid && pid != -1) 2773 1 /** Should check and make sure process exited... **/ 2774 1 ; 2775 1 2776 1 return(zepid); 2777 1 } 2778 #endif 2779 2780 /* 2781 * This is an ugly hack for now, since we only use strftime in one 2782 * place..... so far.. 2783 */ 2784 2785 #if defined(NO_STRFTIME) 2786 # include 2903 2904 2905 int strftime(buf, bufsize, fmt, tm) 2906 char *buf; 2907 int bufsize; 2908 char *fmt; 2909 struct tm *tm; 2910 { COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 9 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 2911 1 sprintf(buf, "%4d%02d%02d%02d%02d%02d\n", 2912 1 tm->tm_year, tm->tm_mon+1,tm->tm_mday, 2913 1 tm->tm_hour, tm->tm_mon, tm->tm_sec); 2914 1 } 2915 2916 #endif 2917 2918 2919 /* 2920 * This code was stolen from cnews. Modified to make "newenv" static so 2921 * that realloc() can be used on subsequent calls to avoid memory leaks. 2922 * 2923 * We only need this if Configure said there isn't a putenv() in libc. 2924 */ 2925 2926 #ifndef VMS 2927 X #ifdef NO_PUTENV /*{*/ 2928 X 2929 X /* peculiar return values */ 2930 X #define WORKED 0 2931 X #define FAILED 1 2932 X 2933 X int 2934 X putenv(var) /* put var in the environment */ 2935 X char *var; 2936 X { 2937 X register char **envp; 2938 X register int oldenvcnt; 2939 X extern char **environ; 2940 X static char **newenv = NULL; 2941 X 2942 X /* count variables, look for var */ 2943 X for (envp = environ; *envp != 0; envp++) { 2944 X register char *varp = var, *ep = *envp; 2945 X register int namesame; 2946 X 2947 X namesame = 0; 2948 X for (; *varp == *ep && *varp != '\0'; ++ep, ++varp) 2949 X if (*varp == '=') 2950 X namesame = 1; 2951 X if (*varp == *ep && *ep == '\0') 2952 X return WORKED; /* old & new var's are the same */ 2953 X if (namesame) { 2954 X *envp = var; /* replace var with new value */ 2955 X return WORKED; 2956 X } 2957 X } 2958 X oldenvcnt = envp - environ; 2959 X 2960 X /* allocate new environment with room for one more variable */ 2961 X if (newenv == NULL) 2962 X newenv = (char **)malloc((unsigned)((oldenvcnt+1+1)*sizeof(*envp))); 2963 X else 2964 X newenv = (char **)realloc((char *)newenv, (unsigned)((oldenvcnt+1+1)*sizeof(*envp))); 2965 X if (newenv == NULL) 2966 X return FAILED; 2967 X COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 10 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 2968 X /* copy old environment pointers, add var, switch environments */ 2969 X (void) bcopy((char *)environ, (char *)newenv, oldenvcnt*sizeof(*envp)); 2970 X newenv[oldenvcnt] = var; 2971 X newenv[oldenvcnt+1] = NULL; 2972 X environ = newenv; 2973 X return WORKED; 2974 X } 2975 X 2976 X #endif /* NO_PUTENV */ 2977 #else 2978 /* OpenVMS has no putenv() function. So we'll make one ;-) */ 2979 2980 2981 /* peculiar return values */ 2982 #define WORKED 0 2983 #define FAILED 1 2984 2985 int 2986 putenv(var) /* put var in the environment */ 2987 char *var; 2988 { /* evenutally, we'll need to actually create a symbol 2989 1 (local to the context) for that variable */ 2990 1 return(WORKED); 2991 1 } 2992 #endif 2993 2994 #ifdef NO_FGETPWENT 2995 X struct passwd * 2996 X fgetpwent(f) 2997 X FILE *f; 2998 X { 2999 X static char input[256]; 3000 X static struct passwd *p = NULL; 3001 X char *cp, *cp2; 3002 X 3003 X if (p == NULL) { 3004 X p = (struct passwd *) malloc(sizeof(struct passwd)); 3005 X } 3006 X 3007 X if (fgets(input, 256, f) == NULL) 3008 X return(NULL); 3009 X 3010 X /* Username */ 3011 X cp = strchr(input, ':'); 3012 X if (cp == NULL) return(NULL); 3013 X 3014 X *cp = '\0'; cp++; 3015 X p->pw_name = input; 3016 X 3017 X /* Password */ 3018 X cp2 = strchr(cp, ':'); 3019 X if (cp2 == NULL) return(NULL); 3020 X *cp2 = '\0'; cp2++; 3021 X p->pw_passwd = cp; 3022 X 3023 X /* UID */ 3024 X cp = strchr(cp2, ':'); COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 11 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 3025 X if (cp == NULL) return(NULL); 3026 X 3027 X *cp = '\0'; cp++; 3028 X p->pw_uid = atoi(cp2); 3029 X 3030 X /* GID */ 3031 X cp2 = strchr(cp, ':'); 3032 X if (cp2 == NULL) return(NULL); 3033 X *cp2 = '\0'; cp2++; 3034 X p->pw_gid = atoi(cp); 3035 X 3036 X /* GECOS */ 3037 X cp = strchr(cp2, ':'); 3038 X if (cp == NULL) return(NULL); 3039 X *cp = '\0'; cp++; 3040 X p->pw_gecos = cp2; 3041 X 3042 X /* Home dir */ 3043 X cp2 = strchr(cp, ':'); 3044 X if (cp2 == NULL) return(NULL); 3045 X *cp2 = '\0'; cp2++; 3046 X p->pw_dir = cp; 3047 X 3048 X /* Shell */ 3049 X p->pw_shell = cp2; 3050 X 3051 X return(p); 3052 X } 3053 #endif /* NO_FGETPWENT */ 3054 3055 #if defined(VMS) && defined(MULTINET) 3056 #if ( defined(CLIENT_LOGGER) || defined(TELNET_TRACE) || defined(VMS_SERVER)) 3057 X /* 3058 X * JL Wilkinson 16-Jul-1994 Merged in TGV's syslog() functions to allow 3059 X * the CLIENT_LOGGER and TELNET_TRACE functionality to work with 3060 X * Multinet. Not tested against other VMS TCP/IP agents, and *NOT 3061 X * SUPPORTED* thru TGV -- please don't anybody ask TGV for help in using 3062 X * this. Somebody who wants to use it can Email me or the 3063 X * VMSGopher-L@trln.lib.unc.edu group and I'll try to assist them for 3064 X * MULTINET only (JLW@psulias.psu.edu). Basic documentation is in 3065 X * the file [.doc]clientlogging.vms. 3066 X */ 3067 X 3068 X 3069 X #include "syslog.h" 3070 X 3071 X /* 3072 X * Copyright (C) 1992 TGV, Incorporated 3073 X */ 3074 X 3075 X /* 3076 X * Copyright (c) 1983 Regents of the University of California. 3077 X * All rights reserved. The Berkeley software License Agreement 3078 X * specifies the terms and conditions for redistribution. 3079 X */ 3080 X 3081 X #ifndef lint COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 12 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 3082 X static char sccsid[] = "@(#)syslog.c 5.3 (Berkeley) 9/17/85"; 3083 X #endif /* not lint */ 3084 X 3085 X /* 3086 X * SYSLOG -- print message on log file 3087 X * 3088 X * This routine looks a lot like printf, except that it 3089 X * outputs to the log file instead of the standard output. 3090 X * Also: 3091 X * adds a timestamp, 3092 X * prints the module name in front of the message, 3093 X * has some other formatting types (or will sometime), 3094 X * adds a newline on the end of the message. 3095 X * 3096 X * The output of this routine is intended to be read by /etc/syslogd. 3097 X * 3098 X * Author: Eric Allman 3099 X * Modified to use UNIX domain IPC by Ralph Campbell 3100 X */ 3101 X 3102 X #include /* JDB */ 3103 X #include /* JLW */ 3104 X #include /* JLW */ 3105 X 3106 X #include 3107 X #include 3108 X #include 3109 X #include 3110 X 3111 X #ifndef _sys_syslog_h 3112 X #include "syslog.h" /* was -- JLW */ 3113 X #endif 3114 X #include 3115 X #ifdef __ALPHA 3116 X #include 3117 X #endif /* __ALPHA */ 3118 X 3119 X #define MAXLINE 1024 /* max message size */ 3120 X 3121 X #define PRIMASK(p) (1 << ((p) & LOG_PRIMASK)) 3122 X #define PRIFAC(p) (((p) & LOG_FACMASK) >> 3) 3123 X #define IMPORTANT LOG_ERR 3124 X 3125 X static char logname[] = "/dev/log"; 3126 X static char ctty[] = "/dev/console"; 3127 X static int LogFile = -1; /* fd for log */ 3128 X static int LogStat = 0; /* status bits, set by openlog() */ 3129 X static char *LogTag = "syslog"; /* string to tag the entry with */ 3130 X static int LogMask = 0xff; /* mask of priorities to be logged */ 3131 X static int LogFacility = LOG_USER; /* default facility code */ 3132 X 3133 X static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */ 3134 X 3135 X #ifdef ORIG 3136 X extern int errno; 3137 X extern int sys_nerr; 3138 X extern char *sys_errlist[]; COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 13 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 3139 X #endif 3140 X 3141 X #ifndef VMS$TrnLNM /* JLW -- use SYS$TRNLNM() instead of VMS$TrnLNM() */ 3142 X #include 3143 X static 3144 X int i, junk, buf_len; 3145 X int no_case = LNM$M_CASE_BLIND; 3146 X static $DESCRIPTOR(lname_desc,"MULTINET_SYSLOG_DESTINATION"); 3147 X static $DESCRIPTOR(tabnam,"LNM$SYSTEM_TABLE"); 3148 X char syslogging_status[256]; 3149 X struct itmlst 3150 X { 3151 X short int buf_len; 3152 X short int item_code; 3153 X char *buffer; 3154 X int *buf_length; 3155 X }; 3156 X static 3157 X struct itmlst 3158 X item_str[] = { {4,LNM$_INDEX,(char *)&i,&junk}, 3159 X {0,LNM$_STRING,0,&buf_len}, 3160 X {0,0,0,0}}; 3161 X #endif 3162 X 3163 X char *vms_errno_string(); 3164 X 3165 X #ifdef __ALPHA 3166 X syslog(va_alist) 3167 X va_dcl 3168 X #else /* __ALPHA */ 3169 X syslog(pri, fmt, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9) 3170 X int pri; 3171 X char *fmt; 3172 X #endif /* __ALPHA */ 3173 X { 3174 X char buf[MAXLINE + 1], outline[MAXLINE + 1]; 3175 X register char *b, *f, *o; 3176 X register int c; 3177 X long now; 3178 X int pid; 3179 X #ifdef ORIG 3180 X int pid, olderrno = errno; 3181 X #endif 3182 X #ifdef __ALPHA 3183 X int pri, numargs; 3184 X char *fmt; 3185 X __int64 p0,p1,p2,p3,p4,p5,p6,p7,p8,p9; 3186 X va_list ap; 3187 X 3188 X va_start(ap); 3189 X va_count(numargs); 3190 X 3191 X pri = va_arg(ap, int); 3192 X fmt = va_arg(ap, char *); 3193 X 3194 X if (numargs > 2) p0 = va_arg(ap, __int64); 3195 X if (numargs > 3) p1 = va_arg(ap, __int64); COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 14 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 3196 X if (numargs > 4) p2 = va_arg(ap, __int64); 3197 X if (numargs > 5) p3 = va_arg(ap, __int64); 3198 X if (numargs > 6) p4 = va_arg(ap, __int64); 3199 X if (numargs > 7) p5 = va_arg(ap, __int64); 3200 X if (numargs > 8) p6 = va_arg(ap, __int64); 3201 X if (numargs > 9) p7 = va_arg(ap, __int64); 3202 X if (numargs > 10) p8 = va_arg(ap, __int64); 3203 X if (numargs > 11) p9 = va_arg(ap, __int64); 3204 X 3205 X #endif /* __ALPHA */ 3206 X 3207 X 3208 X /* see if we should just throw out this message */ 3209 X if (pri <= 0 || PRIFAC(pri) >= LOG_NFACILITIES || (PRIMASK(pri) & LogMask) == 0) 3210 X return; 3211 X if (LogFile < 0) 3212 X openlog(LogTag, LogStat & ~LOG_ODELAY, 0); 3213 X 3214 X /* set default facility if none specified */ 3215 X if ((pri & LOG_FACMASK) == 0) 3216 X pri |= LogFacility; 3217 X 3218 X /* build the message */ 3219 X o = outline; 3220 X sprintf(o, "<%d>", pri); 3221 X o += strlen(o); 3222 X time(&now); 3223 X sprintf(o, "%.15s ", ctime(&now) + 4); 3224 X o += strlen(o); 3225 X if (LogTag && strcmp(LogTag, "dprintf")) { 3226 X strcpy(o, LogTag); 3227 X o += strlen(o); 3228 X } 3229 X if (LogStat & LOG_PID) { 3230 X sprintf(o, "[Pid 0x%x]", getpid()); 3231 X o += strlen(o); 3232 X } 3233 X if (LogTag && strcmp(LogTag, "dprintf")) { 3234 X strcpy(o, ": "); 3235 X o += 2; 3236 X } 3237 X 3238 X b = buf; 3239 X f = fmt; 3240 X while ((c = *f++) != '\0' && c != '\n' && b < &buf[MAXLINE]) { 3241 X if (c != '%') { 3242 X *b++ = c; 3243 X continue; 3244 X } 3245 X if ((c = *f++) != 'm') { 3246 X *b++ = '%'; 3247 X *b++ = c; 3248 X continue; 3249 X } 3250 X sprintf(b, "%s", vms_errno_string() ); 3251 X b += strlen(b); 3252 X } COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 15 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 3253 X *b++ = '\n'; 3254 X *b = '\0'; 3255 X sprintf(o, buf, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); 3256 X c = strlen(outline); 3257 X if (c > MAXLINE) 3258 X c = MAXLINE; 3259 X 3260 X /* output the message to the local logger */ 3261 X #ifndef VMS$TrnLNM 3262 X item_str[1].buf_len = 255; 3263 X item_str[1].buffer = syslogging_status; 3264 X i = 0; 3265 X if (SS$_NORMAL == 3266 X SYS$TRNLNM(&no_case,&tabnam,&lname_desc,0,&item_str)) { 3267 X #else 3268 X if (VMS$TrnLNM("MULTINET_SYSLOG_DESTINATION",0)) { 3269 X #endif 3270 X if (sendto(LogFile, outline, c, 0, &SyslogAddr, sizeof SyslogAddr) >= 0) { 3271 X return 1; 3272 X } 3273 X } 3274 X #ifdef Send_Oper 3275 X if (!(LogStat & LOG_CONS) && (pri & LOG_PRIMASK) <= LOG_ERR) 3276 X return -1; 3277 X 3278 X /* Output the message to the console, add the LogTag so it looks 3279 X * like syslog(), even if syslog is disabled and we're using OPCOM. 3280 X * make sure there is a newline. 3281 X */ 3282 X 3283 X o = outline; 3284 X if (LogTag && strcmp(LogTag, "dprintf")) { 3285 X strcpy(o, LogTag); 3286 X o += strlen(o); 3287 X *o++ = ':'; 3288 X *o++ = ' '; 3289 X } 3290 X sprintf(o, fmt, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); 3291 X c = strlen(outline); 3292 X if (c > MAXLINE) 3293 X c = MAXLINE-1; 3294 X if ( outline[c-1] != '\n' ) { 3295 X outline[c] = '\n'; 3296 X outline[c+1] = '\0'; 3297 X } 3298 X Send_Oper(outline); 3299 X #endif 3300 X return 1; 3301 X } 3302 X 3303 X /* 3304 X * OPENLOG -- open system log 3305 X */ 3306 X 3307 X openlog(ident, logstat, logfac) 3308 X char *ident; 3309 X int logstat, logfac; COMPATIBLE 22-SEP-1995 18:33:37 VAX C V3.2-044 Page 16 V1.0 22-SEP-1995 18:32:57 [GOPHER.G2.VMS2_13.OBJECT]COMPATIBLE.C;9 (1) 3310 X { 3311 X if (ident != NULL) 3312 X LogTag = ident; 3313 X LogStat = logstat; 3314 X if (logfac != 0) 3315 X LogFacility = logfac & LOG_FACMASK; 3316 X if (LogFile >= 0) 3317 X return; 3318 X SyslogAddr.sa_family = AF_UNIX; 3319 X strncpy(SyslogAddr.sa_data, logname, sizeof SyslogAddr.sa_data); 3320 X if (!(LogStat & LOG_ODELAY)) { 3321 X LogFile = socket(AF_UNIX, SOCK_DGRAM, 0); 3322 X #ifdef ORIG 3323 X fcntl(LogFile, F_SETFD, 1); 3324 X #endif 3325 X } 3326 X } 3327 X 3328 X /* 3329 X * CLOSELOG -- close the system log 3330 X */ 3331 X closelog() 3332 X { 3333 X 3334 X (void) close(LogFile); 3335 X LogFile = -1; 3336 X } 3337 X 3338 X /* 3339 X * SETLOGMASK -- set the log mask level 3340 X */ 3341 X setlogmask(pmask) 3342 X int pmask; 3343 X { 3344 X int omask; 3345 X 3346 X omask = LogMask; 3347 X if (pmask != 0) 3348 X LogMask = pmask; 3349 X return (omask); 3350 X } 3351 X 3352 #endif 3353 #endif Command Line ------------ CC/INCL=([-],[-.OBJECT])/DEFINE=(MULTINET=1,DEBUGGING,__VMS)/DEBUG/NOOPT/OBJ=[.VAX.DBG]/LIS=[.VAX.LIS] COMPATIBLE .