]>
Commit | Line | Data |
---|---|---|
e61abf83 UD |
1 | /* Copyright (c) 1997 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. | |
3 | Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997. | |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Library General Public License as | |
7 | published by the Free Software Foundation; either version 2 of the | |
8 | License, or (at your option) any later version. | |
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 | |
13 | Library General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Library General Public | |
16 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
17 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
18 | Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | #include <stdio.h> | |
21 | #include <stdlib.h> | |
22 | #include <string.h> | |
23 | #include <rpcsvc/nis.h> | |
24 | #include <rpcsvc/nislib.h> | |
25 | ||
5ae9d168 UD |
26 | |
27 | static const char cold_start_file[] = "/var/nis/NIS_COLD_START"; | |
28 | ||
e61abf83 UD |
29 | directory_obj * |
30 | readColdStartFile (void) | |
31 | { | |
32 | XDR xdrs; | |
33 | FILE *in; | |
34 | directory_obj obj; | |
35 | ||
5ae9d168 | 36 | in = fopen (cold_start_file, "rb"); |
e61abf83 UD |
37 | if (in == NULL) |
38 | { | |
5ae9d168 | 39 | printf (_("Error while opening %s for reading: %m"), cold_start_file); |
e61abf83 UD |
40 | return NULL; |
41 | } | |
42 | memset (&obj, '\0', sizeof (obj)); | |
43 | xdrstdio_create (&xdrs, in, XDR_DECODE); | |
44 | if (!xdr_directory_obj (&xdrs, &obj)) | |
45 | { | |
5ae9d168 | 46 | printf (_("Error while reading %s: %m"), cold_start_file); |
e61abf83 UD |
47 | return NULL; |
48 | } | |
49 | ||
50 | return nis_clone_directory (&obj, NULL); | |
51 | } | |
52 | ||
53 | bool_t | |
54 | writeColdStartFile (const directory_obj *obj) | |
55 | { | |
56 | XDR xdrs; | |
57 | FILE *out; | |
58 | ||
5ae9d168 | 59 | out = fopen (cold_start_file, "wb"); |
e61abf83 | 60 | if (out == NULL) |
5ae9d168 UD |
61 | { |
62 | printf (_("Error while opening %s for writing: %m"), cold_start_file); | |
63 | return FALSE; | |
64 | } | |
e61abf83 UD |
65 | |
66 | xdrstdio_create (&xdrs, out, XDR_ENCODE); | |
67 | /* XXX The following cast is bad! Shouldn't the XDR functions take | |
68 | pointers to const objects? */ | |
69 | if (!xdr_directory_obj (&xdrs, (directory_obj *) obj)) | |
70 | { | |
5ae9d168 | 71 | printf (_("Error while writing %s: %m"), cold_start_file); |
e61abf83 UD |
72 | return FALSE; |
73 | } | |
74 | ||
75 | return TRUE; | |
76 | } | |
77 | ||
78 | nis_object * | |
79 | nis_read_obj (const char *name) | |
80 | { | |
81 | XDR xdrs; | |
82 | FILE *in; | |
83 | nis_object obj; | |
84 | ||
85 | in = fopen (name, "rb"); | |
86 | if (in == NULL) | |
87 | return NULL; | |
88 | ||
89 | memset (&obj, '\0', sizeof (obj)); | |
90 | xdrstdio_create (&xdrs, in, XDR_DECODE); | |
91 | if (!xdr_nis_object (&xdrs, &obj)) | |
92 | return NULL; | |
93 | ||
94 | return nis_clone_object (&obj, NULL); | |
95 | } | |
96 | ||
97 | bool_t | |
98 | nis_write_obj (const char *name, const nis_object *obj) | |
99 | { | |
100 | XDR xdrs; | |
101 | FILE *out; | |
102 | ||
103 | out = fopen (name, "wb"); | |
104 | if (out == NULL) | |
105 | return FALSE; | |
106 | ||
107 | xdrstdio_create (&xdrs, out, XDR_ENCODE); | |
108 | /* XXX The following cast is bad! Shouldn't the XDR functions take | |
109 | pointers to const objects? */ | |
110 | if (!xdr_nis_object (&xdrs, (nis_object *) obj)) | |
111 | return FALSE; | |
112 | ||
113 | return TRUE; | |
114 | } |