Back to index

glibc  2.9
nis_add.c
Go to the documentation of this file.
00001 /* Copyright (C) 1997, 1998, 2004 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Thorsten Kukuk <kukuk@uni-paderborn.de>, 1997.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <string.h>
00021 #include <rpcsvc/nis.h>
00022 
00023 #include "nis_xdr.h"
00024 #include "nis_intern.h"
00025 
00026 nis_result *
00027 nis_add (const_nis_name name, const nis_object *obj2)
00028 {
00029   nis_object obj;
00030   nis_result *res;
00031   nis_error status;
00032   struct ns_request req;
00033   size_t namelen = strlen (name);
00034   char buf1 [namelen + 20];
00035   char buf4 [namelen + 20];
00036 
00037   res = calloc (1, sizeof (nis_result));
00038   if (res == NULL)
00039     return NULL;
00040 
00041   req.ns_name = (char *)name;
00042 
00043   memcpy (&obj, obj2, sizeof (nis_object));
00044 
00045   if (obj.zo_name == NULL || obj.zo_name[0] == '\0')
00046     obj.zo_name = nis_leaf_of_r (name, buf1, sizeof (buf1));
00047 
00048   if (obj.zo_owner == NULL || obj.zo_owner[0] == '\0')
00049     obj.zo_owner = nis_local_principal ();
00050 
00051   if (obj.zo_group == NULL || obj.zo_group[0] == '\0')
00052     obj.zo_group = nis_local_group ();
00053 
00054   obj.zo_domain = nis_domain_of_r (name, buf4, sizeof (buf4));
00055 
00056   req.ns_object.ns_object_val = nis_clone_object (&obj, NULL);
00057   if (req.ns_object.ns_object_val == NULL)
00058     {
00059       NIS_RES_STATUS (res) = NIS_NOMEMORY;
00060       return res;
00061     }
00062   req.ns_object.ns_object_len = 1;
00063 
00064   status = __do_niscall (req.ns_object.ns_object_val[0].zo_domain,
00065                       NIS_ADD, (xdrproc_t) _xdr_ns_request,
00066                       (caddr_t) &req, (xdrproc_t) _xdr_nis_result,
00067                       (caddr_t) res, MASTER_ONLY, NULL);
00068   if (status != RPC_SUCCESS)
00069     NIS_RES_STATUS (res) = status;
00070 
00071   nis_destroy_object (req.ns_object.ns_object_val);
00072 
00073   return res;
00074 }
00075 libnsl_hidden_def (nis_add)