File: ypbind3_binding_dup.c

package info (click to toggle)
yp-tools 4.2.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,288 kB
  • sloc: ansic: 4,192; sh: 1,081; makefile: 59; sed: 16
file content (103 lines) | stat: -rw-r--r-- 3,232 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* Copyright (C) 2014, 2016 Thorsten Kukuk
   Author: Thorsten Kukuk <kukuk@suse.de>

   This library is free software: you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public License
   in version 2.1 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#if defined(HAVE_YPBIND3)

#include <string.h>
#include <rpcsvc/yp_prot.h>
#include "internal.h"

struct ypbind3_binding *
__ypbind3_binding_dup (struct ypbind3_binding *src)
{
#define copy_str(source, dest) \
  if (source != NULL) \
    { \
      dest = strdup (source); \
      if (dest == NULL) \
        { \
          __ypbind3_binding_free (dst); \
          return NULL; \
        } \
    }

  struct ypbind3_binding *dst;
  unsigned long i;

  dst = calloc(1, sizeof (struct ypbind3_binding));
  if (dst == NULL)
    return NULL;

  dst->ypbind_nconf = calloc (1, sizeof (struct netconfig));
  if (dst->ypbind_nconf == NULL)
    {
      __ypbind3_binding_free (dst);
      return NULL;
    }
  dst->ypbind_svcaddr = calloc(1, sizeof (struct netbuf));
  if (dst->ypbind_svcaddr == NULL)
    {
      __ypbind3_binding_free (dst);
      return NULL;
    }
  dst->ypbind_hi_vers = src->ypbind_hi_vers;
  dst->ypbind_lo_vers = src->ypbind_lo_vers;
  if (src->ypbind_servername)
    dst->ypbind_servername =
      strdup(src->ypbind_servername);

  copy_str (src->ypbind_nconf->nc_netid, dst->ypbind_nconf->nc_netid);
  dst->ypbind_nconf->nc_semantics = src->ypbind_nconf->nc_semantics;
  dst->ypbind_nconf->nc_flag = src->ypbind_nconf->nc_flag;
  copy_str (src->ypbind_nconf->nc_protofmly, dst->ypbind_nconf->nc_protofmly);
  copy_str (src->ypbind_nconf->nc_proto, dst->ypbind_nconf->nc_proto);
  copy_str (src->ypbind_nconf->nc_device, dst->ypbind_nconf->nc_device);
  dst->ypbind_nconf->nc_nlookups = src->ypbind_nconf->nc_nlookups;

  dst->ypbind_nconf->nc_lookups = calloc (src->ypbind_nconf->nc_nlookups,
                                          sizeof (char *));
  if (dst->ypbind_nconf->nc_lookups == NULL)
    {
      __ypbind3_binding_free (dst);
      return NULL;
    }
  for (i = 0; i < src->ypbind_nconf->nc_nlookups; i++)
    dst->ypbind_nconf->nc_lookups[i] =
      src->ypbind_nconf->nc_lookups[i] ?
      strdup (src->ypbind_nconf->nc_lookups[i]) : NULL;

  for (i = 0; i < 8; i++)
    dst->ypbind_nconf->nc_unused[i] = src->ypbind_nconf->nc_unused[i];

  dst->ypbind_svcaddr->maxlen = src->ypbind_svcaddr->maxlen;
  dst->ypbind_svcaddr->len = src->ypbind_svcaddr->len;
  dst->ypbind_svcaddr->buf = malloc (src->ypbind_svcaddr->maxlen);
  if (dst->ypbind_svcaddr->buf == NULL)
    {
      __ypbind3_binding_free (dst);
      return NULL;
    }
  memcpy (dst->ypbind_svcaddr->buf, src->ypbind_svcaddr->buf,
          dst->ypbind_svcaddr->len);

  return dst;
#undef copy_str
}

#endif