585214a3b45658040ec4db4b0cba5aa66dc42cd9
[platform/upstream/glibc.git] / nis / nis_checkpoint.c
1 /* Copyright (c) 1997, 1998 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 <rpcsvc/nis.h>
21
22 #include "nis_xdr.h"
23 #include "nis_intern.h"
24
25 nis_result *
26 nis_checkpoint(const_nis_name dirname)
27 {
28   nis_result *res;
29
30   res = calloc (1, sizeof (nis_result));
31   if (res == NULL)
32     return NULL;
33
34   if (dirname != NULL)
35     {
36       nis_result *res2;
37       u_int i;
38
39       res2 = nis_lookup (dirname, EXPAND_NAME);
40       if (NIS_RES_STATUS (res2) != NIS_SUCCESS)
41         return res2;
42
43       /* Check if obj is really a diryectory object */
44       if (__type_of (NIS_RES_OBJECT (res2)) != NIS_DIRECTORY_OBJ)
45         {
46           nis_freeresult (res);
47           NIS_RES_STATUS (res) = NIS_INVALIDOBJ;
48           return res;
49         }
50
51       for (i = 0;
52            i < NIS_RES_OBJECT (res2)->DI_data.do_servers.do_servers_len; ++i)
53         {
54           cp_result cpres;
55
56           memset (&cpres, '\0', sizeof (cp_result));
57           if (__do_niscall2 (&NIS_RES_OBJECT(res2)->DI_data.do_servers.do_servers_val[i],
58                              1, NIS_CHECKPOINT, (xdrproc_t) _xdr_nis_name,
59                              (caddr_t) &dirname, (xdrproc_t) _xdr_cp_result,
60                              (caddr_t) &cpres, 0, NULL, NULL) != NIS_SUCCESS)
61             NIS_RES_STATUS (res) = NIS_RPCERROR;
62           else
63             {
64               NIS_RES_STATUS (res) = cpres.cp_status;
65               res->zticks += cpres.cp_zticks;
66               res->dticks += cpres.cp_dticks;
67             }
68         }
69       nis_freeresult (res2);
70     }
71   else
72     NIS_RES_STATUS (res) = NIS_NOSUCHNAME;
73
74   return res;
75 }