]>
Commit | Line | Data |
---|---|---|
bfff8b1b | 1 | /* Copyright (c) 1997-2017 Free Software Foundation, Inc. |
e61abf83 | 2 | This file is part of the GNU C Library. |
32abdb71 | 3 | Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997. |
e61abf83 UD |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
e61abf83 UD |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
e61abf83 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
e61abf83 UD |
18 | |
19 | #include <stdio.h> | |
20 | #include <stdlib.h> | |
21 | #include <string.h> | |
22 | #include <rpcsvc/nis.h> | |
91eee4dd | 23 | #include "nis_xdr.h" |
5ae9d168 | 24 | |
eca086a6 UD |
25 | typedef bool_t (*iofct_t) (XDR *, void *); |
26 | typedef void (*freefct_t) (void *); | |
0ecb606c | 27 | |
eca086a6 UD |
28 | |
29 | static void * | |
30 | read_nis_obj (const char *name, iofct_t readfct, freefct_t freefct, | |
31 | size_t objsize) | |
e61abf83 | 32 | { |
312be3f9 | 33 | FILE *in = fopen (name, "rce"); |
e61abf83 | 34 | if (in == NULL) |
3e5f5557 | 35 | return NULL; |
e61abf83 | 36 | |
eca086a6 | 37 | void *obj = calloc (1, objsize); |
3d8fa13a UD |
38 | |
39 | if (obj != NULL) | |
e852e889 | 40 | { |
7440c23e | 41 | XDR xdrs; |
3d8fa13a | 42 | xdrstdio_create (&xdrs, in, XDR_DECODE); |
eca086a6 | 43 | bool_t status = readfct (&xdrs, obj); |
3d8fa13a UD |
44 | xdr_destroy (&xdrs); |
45 | ||
46 | if (!status) | |
47 | { | |
eca086a6 | 48 | freefct (obj); |
3d8fa13a UD |
49 | obj = NULL; |
50 | } | |
e852e889 | 51 | } |
3d8fa13a UD |
52 | |
53 | fclose (in); | |
54 | ||
55 | return obj; | |
e61abf83 UD |
56 | } |
57 | ||
eca086a6 UD |
58 | static bool_t |
59 | write_nis_obj (const char *name, const void *obj, iofct_t writefct) | |
e61abf83 | 60 | { |
312be3f9 | 61 | FILE *out = fopen (name, "wce"); |
e61abf83 | 62 | if (out == NULL) |
3e5f5557 | 63 | return FALSE; |
e61abf83 | 64 | |
eca086a6 | 65 | XDR xdrs; |
e61abf83 | 66 | xdrstdio_create (&xdrs, out, XDR_ENCODE); |
eca086a6 | 67 | bool_t status = writefct (&xdrs, (void *) obj); |
a53bad16 UD |
68 | xdr_destroy (&xdrs); |
69 | fclose (out); | |
e61abf83 | 70 | |
a53bad16 | 71 | return status; |
e61abf83 UD |
72 | } |
73 | ||
e61abf83 | 74 | |
eca086a6 | 75 | static const char cold_start_file[] = "/var/nis/NIS_COLD_START"; |
e61abf83 | 76 | |
eca086a6 UD |
77 | directory_obj * |
78 | readColdStartFile (void) | |
79 | { | |
80 | return read_nis_obj (cold_start_file, (iofct_t) _xdr_directory_obj, | |
81 | (freefct_t) nis_free_directory, sizeof (directory_obj)); | |
82 | } | |
1e4d83f6 | 83 | libnsl_hidden_nolink_def (readColdStartFile, GLIBC_2_1) |
32abdb71 | 84 | |
eca086a6 UD |
85 | bool_t |
86 | writeColdStartFile (const directory_obj *obj) | |
87 | { | |
88 | return write_nis_obj (cold_start_file, obj, (iofct_t) _xdr_directory_obj); | |
89 | } | |
1e4d83f6 | 90 | libnsl_hidden_nolink_def (writeColdStartFile, GLIBC_2_1) |
e61abf83 | 91 | |
eca086a6 UD |
92 | nis_object * |
93 | nis_read_obj (const char *name) | |
94 | { | |
95 | return read_nis_obj (name, (iofct_t) _xdr_nis_object, | |
96 | (freefct_t) nis_free_object, sizeof (nis_object)); | |
e61abf83 | 97 | } |
1e4d83f6 | 98 | libnsl_hidden_nolink_def (nis_read_obj, GLIBC_2_1) |
e61abf83 UD |
99 | |
100 | bool_t | |
101 | nis_write_obj (const char *name, const nis_object *obj) | |
102 | { | |
eca086a6 | 103 | return write_nis_obj (name, obj, (iofct_t) _xdr_nis_object); |
e61abf83 | 104 | } |
1e4d83f6 | 105 | libnsl_hidden_nolink_def (nis_write_obj, GLIBC_2_1) |