]> git.ipfire.org Git - thirdparty/glibc.git/blame - nis/nis_file.c
* nis/nis_xdr.c: Remove unnecessary cast which might hide bugs.
[thirdparty/glibc.git] / nis / nis_file.c
CommitLineData
a334319f 1/* Copyright (c) 1997, 1998, 1999, 2004 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
AJ
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
e61abf83
UD
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <rpcsvc/nis.h>
91eee4dd 24#include "nis_xdr.h"
5ae9d168 25
a334319f 26static const char cold_start_file[] = "/var/nis/NIS_COLD_START";
0ecb606c 27
a334319f
UD
28directory_obj *
29readColdStartFile (void)
e61abf83 30{
a334319f 31 FILE *in = fopen (cold_start_file, "rc");
e61abf83 32 if (in == NULL)
3e5f5557 33 return NULL;
e61abf83 34
a334319f 35 directory_obj *obj = calloc (1, sizeof (directory_obj));
3d8fa13a
UD
36
37 if (obj != NULL)
e852e889 38 {
7440c23e 39 XDR xdrs;
3d8fa13a 40 xdrstdio_create (&xdrs, in, XDR_DECODE);
a334319f 41 bool_t status = _xdr_directory_obj (&xdrs, obj);
3d8fa13a
UD
42 xdr_destroy (&xdrs);
43
44 if (!status)
45 {
a334319f 46 nis_free_directory (obj);
3d8fa13a
UD
47 obj = NULL;
48 }
e852e889 49 }
3d8fa13a
UD
50
51 fclose (in);
52
53 return obj;
e61abf83 54}
a334319f 55libnsl_hidden_def (readColdStartFile)
e61abf83 56
a334319f
UD
57bool_t
58writeColdStartFile (const directory_obj *obj)
e61abf83 59{
a334319f
UD
60 XDR xdrs;
61 FILE *out;
62 bool_t status;
63
64 out = fopen (cold_start_file, "wb");
e61abf83 65 if (out == NULL)
3e5f5557 66 return FALSE;
e61abf83
UD
67
68 xdrstdio_create (&xdrs, out, XDR_ENCODE);
a334319f 69 status = _xdr_directory_obj (&xdrs, (directory_obj *) obj);
a53bad16
UD
70 xdr_destroy (&xdrs);
71 fclose (out);
e61abf83 72
a53bad16 73 return status;
e61abf83
UD
74}
75
a334319f
UD
76nis_object *
77nis_read_obj (const char *name)
78{
79 XDR xdrs;
80 FILE *in;
81 bool_t status;
82 nis_object *obj;
e61abf83 83
a334319f
UD
84 in = fopen (name, "rb");
85 if (in == NULL)
86 return NULL;
e61abf83 87
a334319f
UD
88 obj = calloc (1, sizeof (nis_object));
89 if (obj == NULL)
90 {
91 fclose (in);
92 return NULL;
93 }
32abdb71 94
a334319f
UD
95 xdrstdio_create (&xdrs, in, XDR_DECODE);
96 status =_xdr_nis_object (&xdrs, obj);
97 xdr_destroy (&xdrs);
98 fclose (in);
e61abf83 99
a334319f
UD
100 if (status)
101 return obj;
102 else
103 {
104 nis_free_object (obj);
105 return NULL;
106 }
e61abf83
UD
107}
108
109bool_t
110nis_write_obj (const char *name, const nis_object *obj)
111{
a334319f
UD
112 XDR xdrs;
113 FILE *out;
114 bool_t status;
115
116 out = fopen (name, "wb");
117 if (out == NULL)
118 return FALSE;
119
120 xdrstdio_create (&xdrs, out, XDR_ENCODE);
121 status = _xdr_nis_object (&xdrs, (nis_object *) obj);
122 xdr_destroy (&xdrs);
123 fclose (out);
124
125 return status;
e61abf83 126}