Print this page
7126 NSS_XbyY_FINI has too much logic for a function-like macro

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/gen/nss_common.c
          +++ new/usr/src/lib/libc/port/gen/nss_common.c
↓ open down ↓ 1016 lines elided ↑ open up ↑
1017 1017          unsigned int *status_vec_p = _nss_status_vec_p();
1018 1018  
1019 1019          return ((status_vec_p != NULL) ? *status_vec_p : (1 << NSS_UNAVAIL));
1020 1020  }
1021 1021  
1022 1022  static void
1023 1023  output_loop_diag_a(
1024 1024          int n,
1025 1025          char *dbase,
1026 1026          struct __nsw_lookup_v1 *lkp)
1027      -
1028 1027  {
1029 1028          (void) fprintf(__nss_debug_file,
1030      -                "NSS_retry(%d): '%s': trying '%s' ... ",
1031      -                n, dbase, lkp->service_name);
     1029 +            "NSS_retry(%d): '%s': trying '%s' ... ",
     1030 +            n, dbase, lkp->service_name);
1032 1031          (void) fflush(__nss_debug_file);
1033 1032  
1034 1033  }
1035 1034  
1036 1035  static void
1037 1036  output_loop_diag_b(
1038 1037          nss_status_t res,
1039 1038          struct __nsw_lookup_v1 *lkp)
1040      -
1041 1039  {
1042 1040          (void) fprintf(__nss_debug_file, "result=");
1043 1041          switch (res) {
1044 1042          case NSS_SUCCESS:
1045 1043                  (void) fprintf(__nss_debug_file, "SUCCESS");
1046 1044                  break;
1047 1045          case NSS_NOTFOUND:
1048 1046                  (void) fprintf(__nss_debug_file, "NOTFOUND");
1049 1047                  break;
1050 1048          case NSS_UNAVAIL:
↓ open down ↓ 14 lines elided ↑ open up ↑
1065 1063                  (void) fprintf(__nss_debug_file, "CONTINUE");
1066 1064                  break;
1067 1065          case  __NSW_RETURN:
1068 1066                  (void) fprintf(__nss_debug_file, "RETURN");
1069 1067                  break;
1070 1068          case __NSW_TRYAGAIN_FOREVER:
1071 1069                  (void) fprintf(__nss_debug_file, "TRYAGAIN_FOREVER");
1072 1070                  break;
1073 1071          case __NSW_TRYAGAIN_NTIMES:
1074 1072                  (void) fprintf(__nss_debug_file, "TRYAGAIN_NTIMES (N=%d)",
1075      -                        lkp->max_retries);
     1073 +                    lkp->max_retries);
1076 1074                  break;
1077 1075          case __NSW_TRYAGAIN_PAUSED:
1078 1076                  (void) fprintf(__nss_debug_file, "TRYAGAIN_PAUSED");
1079 1077                  break;
1080 1078          default:
1081 1079                  (void) fprintf(__nss_debug_file, "undefined");
1082 1080          }
1083 1081          (void) fprintf(__nss_debug_file, "\n");
1084 1082  }
1085 1083  
↓ open down ↓ 57 lines elided ↑ open up ↑
1143 1141          if (s == 0) {
1144 1142                  NSS_UNLOCK(rootp);
1145 1143          } else {
1146 1144                  rootp->s = 0;
1147 1145                  NSS_UNREF_UNLOCK(rootp, s);
1148 1146          }
1149 1147  }
1150 1148  
1151 1149  nss_status_t
1152 1150  nss_search(nss_db_root_t *rootp, nss_db_initf_t initf, int search_fnum,
1153      -        void *search_args)
     1151 +    void *search_args)
1154 1152  {
1155 1153          nss_status_t            res = NSS_UNAVAIL;
1156 1154          struct nss_db_state     *s;
1157 1155          int                     n_src;
1158 1156          unsigned int            *status_vec_p;
1159 1157  
1160 1158          /* name service cache daemon divert */
1161 1159          res = _nsc_search(rootp, initf, search_fnum, search_args);
1162 1160          if (res != NSS_TRYLOCAL)
1163 1161                  return (res);
↓ open down ↓ 139 lines elided ↑ open up ↑
1303 1301          if (contextpp == 0) {
1304 1302                  return;
1305 1303          }
1306 1304          cancel_safe_mutex_lock(&contextpp->lock);
1307 1305          nss_setent_u(rootp, initf, contextpp);
1308 1306          cancel_safe_mutex_unlock(&contextpp->lock);
1309 1307  }
1310 1308  
1311 1309  nss_status_t
1312 1310  nss_getent(nss_db_root_t *rootp, nss_db_initf_t initf, nss_getent_t *contextpp,
1313      -        void *args)
     1311 +    void *args)
1314 1312  {
1315 1313          nss_status_t            status;
1316 1314  
1317 1315          if (contextpp == 0) {
1318 1316                  return (NSS_UNAVAIL);
1319 1317          }
1320 1318          cancel_safe_mutex_lock(&contextpp->lock);
1321 1319          status = nss_getent_u(rootp, initf, contextpp, args);
1322 1320          cancel_safe_mutex_unlock(&contextpp->lock);
1323 1321          return (status);
↓ open down ↓ 33 lines elided ↑ open up ↑
1357 1355                          nss_put_backend_u(s, n_src, be);
1358 1356                          contextp->be = 0;  /* Should be unnecessary, but hey */
1359 1357                          NSS_UNREF_UNLOCK(rootp, s);
1360 1358                  }
1361 1359                  contextp->s = 0;
1362 1360          }
1363 1361  }
1364 1362  
1365 1363  static void
1366 1364  nss_setent_u(nss_db_root_t *rootp, nss_db_initf_t initf,
1367      -        nss_getent_t *contextpp)
     1365 +    nss_getent_t *contextpp)
1368 1366  {
1369 1367          nss_status_t            status;
1370 1368          struct nss_db_state     *s;
1371 1369          struct nss_getent_context *contextp;
1372 1370          nss_backend_t           *be;
1373 1371          int                     n_src;
1374 1372  
1375 1373          /* setup process wide context while locked */
1376 1374          if ((contextp = contextpp->ctx) == 0) {
1377 1375                  if ((contextp = libc_malloc(sizeof (*contextp))) == 0) {
↓ open down ↓ 64 lines elided ↑ open up ↑
1442 1440          if (be == 0) {
1443 1441                  /* Things are broken enough that we can't do setent/getent */
1444 1442                  nss_endent_u(rootp, initf, contextpp);
1445 1443                  return;
1446 1444          }
1447 1445          (void) NSS_INVOKE_DBOP(be, NSS_DBOP_SETENT, 0);
1448 1446  }
1449 1447  
1450 1448  static nss_status_t
1451 1449  nss_getent_u(nss_db_root_t *rootp, nss_db_initf_t initf,
1452      -        nss_getent_t *contextpp, void *args)
     1450 +    nss_getent_t *contextpp, void *args)
1453 1451  {
1454 1452          nss_status_t            status;
1455 1453          struct nss_db_state     *s;
1456 1454          struct nss_getent_context *contextp;
1457 1455          int                     n_src;
1458 1456          nss_backend_t           *be;
1459 1457  
1460 1458          if ((contextp = contextpp->ctx) == 0) {
1461 1459                  nss_setent_u(rootp, initf, contextpp);
1462 1460                  if ((contextp = contextpp->ctx) == 0) {
↓ open down ↓ 63 lines elided ↑ open up ↑
1526 1524          }
1527 1525          /* Got to the end of the sources without finding another entry */
1528 1526          end_iter_u(rootp, contextp);
1529 1527          return (NSS_SUCCESS);
1530 1528          /* success is either a successful entry or end of the sources */
1531 1529  }
1532 1530  
1533 1531  /*ARGSUSED*/
1534 1532  static void
1535 1533  nss_endent_u(nss_db_root_t *rootp, nss_db_initf_t initf,
1536      -        nss_getent_t *contextpp)
     1534 +    nss_getent_t *contextpp)
1537 1535  {
1538 1536          nss_status_t            status;
1539 1537          struct nss_getent_context *contextp;
1540 1538  
1541 1539          if ((contextp = contextpp->ctx) == 0) {
1542 1540                  /* nss_endent() on an unused context is a no-op */
1543 1541                  return;
1544 1542          }
1545 1543  
1546 1544          /* notify name service cache daemon */
↓ open down ↓ 100 lines elided ↑ open up ↑
1647 1645  }
1648 1646  
1649 1647  /*
1650 1648   * Switch packed and _nsc (switch->nscd) interfaces
1651 1649   * Return: NSS_SUCCESS (OK to proceed), NSS_ERROR, NSS_NOTFOUND
1652 1650   */
1653 1651  
1654 1652  /*ARGSUSED*/
1655 1653  nss_status_t
1656 1654  nss_pack(void *buffer, size_t bufsize, nss_db_root_t *rootp,
1657      -            nss_db_initf_t initf, int search_fnum, void *search_args)
     1655 +    nss_db_initf_t initf, int search_fnum, void *search_args)
1658 1656  {
1659 1657          nss_pheader_t           *pbuf = (nss_pheader_t *)buffer;
1660 1658          nss_XbyY_args_t         *in = (nss_XbyY_args_t *)search_args;
1661 1659          nss_db_params_t         tparam = { 0 };
1662 1660          nss_status_t            ret = NSS_ERROR;
1663 1661          const char              *dbn;
1664 1662          size_t                  blen, len, off = 0;
1665 1663          char                    *bptr;
1666 1664          struct nss_groupsbymem  *gbm;
1667 1665  
↓ open down ↓ 87 lines elided ↑ open up ↑
1755 1753  }
1756 1754  
1757 1755  /*
1758 1756   * Switch packed and _nsc (switch->nscd) {set/get/end}ent interfaces
1759 1757   * Return: NSS_SUCCESS (OK to proceed), NSS_ERROR, NSS_NOTFOUND
1760 1758   */
1761 1759  
1762 1760  /*ARGSUSED*/
1763 1761  nss_status_t
1764 1762  nss_pack_ent(void *buffer, size_t bufsize, nss_db_root_t *rootp,
1765      -            nss_db_initf_t initf, nss_getent_t *contextpp)
     1763 +    nss_db_initf_t initf, nss_getent_t *contextpp)
1766 1764  {
1767 1765          nss_pheader_t           *pbuf = (nss_pheader_t *)buffer;
1768 1766          struct nss_getent_context *contextp = contextpp->ctx;
1769 1767          nss_status_t            ret = NSS_ERROR;
1770 1768          size_t                  blen, len = 0, off = 0;
1771 1769          char                    *bptr;
1772 1770          nssuint_t               *nptr;
1773 1771  
1774 1772          if (pbuf == NULL || initf == (nss_db_initf_t)NULL) {
1775 1773                  errno = ERANGE;                 /* actually EINVAL */
↓ open down ↓ 53 lines elided ↑ open up ↑
1829 1827   * back to the return buffer.
1830 1828   *
1831 1829   * Note: the digested results are nssuint_t quantities.  _getgroupsbymember
1832 1830   * digests int quantities.  Therefore convert.  Assume input is in nssuint_t
1833 1831   * quantities.  Store in an int array... Assume gid's are <= 32 bits...
1834 1832   */
1835 1833  
1836 1834  /*ARGSUSED*/
1837 1835  nss_status_t
1838 1836  nss_unpack(void *buffer, size_t bufsize, nss_db_root_t *rootp,
1839      -            nss_db_initf_t initf, int search_fnum, void *search_args)
     1837 +    nss_db_initf_t initf, int search_fnum, void *search_args)
1840 1838  {
1841 1839          nss_pheader_t           *pbuf = (nss_pheader_t *)buffer;
1842 1840          nss_XbyY_args_t         *in = (nss_XbyY_args_t *)search_args;
1843 1841          nss_dbd_t               *pdbd;
1844 1842          char                    *dbn;
1845 1843          nss_status_t            status;
1846 1844          char                    *buf;
1847 1845          int                     len;
1848 1846          int                     ret;
1849 1847          int                     i;
↓ open down ↓ 80 lines elided ↑ open up ↑
1930 1928  }
1931 1929  
1932 1930  /*
1933 1931   * Unpack a returned packed {set,get,end}ent arguments buffer
1934 1932   * Return: status, errnos, cookie info and results from requested operation.
1935 1933   */
1936 1934  
1937 1935  /*ARGSUSED*/
1938 1936  nss_status_t
1939 1937  nss_unpack_ent(void *buffer, size_t bufsize, nss_db_root_t *rootp,
1940      -            nss_db_initf_t initf, nss_getent_t *contextpp, void *args)
     1938 +    nss_db_initf_t initf, nss_getent_t *contextpp, void *args)
1941 1939  {
1942 1940          nss_pheader_t           *pbuf = (nss_pheader_t *)buffer;
1943 1941          nss_XbyY_args_t         *in = (nss_XbyY_args_t *)args;
1944 1942          struct nss_getent_context *contextp = contextpp->ctx;
1945 1943          nssuint_t               *nptr;
1946 1944          nssuint_t               cookie;
1947 1945          nss_status_t            status;
1948 1946          char                    *buf;
1949 1947          int                     len;
1950 1948          int                     ret;
↓ open down ↓ 51 lines elided ↑ open up ↑
2002 2000          in->h_errno = (int)pbuf->p_herrno;
2003 2001          return ((nss_status_t)ret);
2004 2002  }
2005 2003  
2006 2004  /*
2007 2005   * Start of _nsc_{search|setent_u|getent_u|endent_u} NSCD interposition funcs
2008 2006   */
2009 2007  
2010 2008  nss_status_t
2011 2009  _nsc_search(nss_db_root_t *rootp, nss_db_initf_t initf, int search_fnum,
2012      -        void *search_args)
     2010 +    void *search_args)
2013 2011  {
2014 2012          nss_pheader_t           *pbuf;
2015 2013          void                    *doorptr = NULL;
2016 2014          size_t                  bufsize = 0;
2017 2015          size_t                  datasize = 0;
2018 2016          nss_status_t            status;
2019 2017  
2020 2018          if (_nsc_proc_is_cache() > 0) {
2021 2019                  /* internal nscd call - don't use the door */
2022 2020                  return (NSS_TRYLOCAL);
↓ open down ↓ 54 lines elided ↑ open up ↑
2077 2075          return (status);
2078 2076  }
2079 2077  
2080 2078  /*
2081 2079   * contact nscd for a cookie or to reset an existing cookie
2082 2080   * if nscd fails (NSS_TRYLOCAL) then set cookie to -1 and
2083 2081   * continue diverting to local
2084 2082   */
2085 2083  nss_status_t
2086 2084  _nsc_setent_u(nss_db_root_t *rootp, nss_db_initf_t initf,
2087      -        nss_getent_t *contextpp)
     2085 +    nss_getent_t *contextpp)
2088 2086  {
2089 2087          nss_status_t            status = NSS_TRYLOCAL;
2090 2088          struct nss_getent_context *contextp = contextpp->ctx;
2091 2089          nss_pheader_t           *pbuf;
2092 2090          void                    *doorptr = NULL;
2093 2091          size_t                  bufsize = 0;
2094 2092          size_t                  datasize = 0;
2095 2093  
2096 2094          /* return if already in local mode */
2097 2095          if (contextp->cookie == NSCD_LOCAL_COOKIE)
↓ open down ↓ 56 lines elided ↑ open up ↑
2154 2152           */
2155 2153          if (doorptr != (void *)pbuf) {
2156 2154                  _nsc_resizedoorbuf(bufsize);
2157 2155                  (void) munmap((void *)doorptr, bufsize);
2158 2156          }
2159 2157          return (status);
2160 2158  }
2161 2159  
2162 2160  nss_status_t
2163 2161  _nsc_getent_u(nss_db_root_t *rootp, nss_db_initf_t initf,
2164      -        nss_getent_t *contextpp, void *args)
     2162 +    nss_getent_t *contextpp, void *args)
2165 2163  {
2166 2164          nss_status_t            status = NSS_TRYLOCAL;
2167 2165          struct nss_getent_context *contextp = contextpp->ctx;
2168 2166          nss_pheader_t           *pbuf;
2169 2167          void                    *doorptr = NULL;
2170 2168          size_t                  bufsize = 0;
2171 2169          size_t                  datasize = 0;
2172 2170  
2173 2171          /* return if already in local mode */
2174 2172          if (contextp->cookie == NSCD_LOCAL_COOKIE)
↓ open down ↓ 46 lines elided ↑ open up ↑
2221 2219           */
2222 2220          if (doorptr != (void *)pbuf) {
2223 2221                  _nsc_resizedoorbuf(bufsize);
2224 2222                  (void) munmap((void *)doorptr, bufsize);
2225 2223          }
2226 2224          return (status);
2227 2225  }
2228 2226  
2229 2227  nss_status_t
2230 2228  _nsc_endent_u(nss_db_root_t *rootp, nss_db_initf_t initf,
2231      -        nss_getent_t *contextpp)
     2229 +    nss_getent_t *contextpp)
2232 2230  {
2233 2231          nss_status_t            status = NSS_TRYLOCAL;
2234 2232          struct nss_getent_context *contextp = contextpp->ctx;
2235 2233          nss_pheader_t           *pbuf;
2236 2234          void                    *doorptr = NULL;
2237 2235          size_t                  bufsize = 0;
2238 2236          size_t                  datasize = 0;
2239 2237  
2240 2238          /* return if already in local mode */
2241 2239          if (contextp->cookie == NSCD_LOCAL_COOKIE)
↓ open down ↓ 49 lines elided ↑ open up ↑
2291 2289  
2292 2290  size_t
2293 2291  _nss_get_bufsizes(int arg)
2294 2292  {
2295 2293          switch (arg) {
2296 2294          case _SC_GETGR_R_SIZE_MAX:
2297 2295                  return (__nss_buflen_group);
2298 2296          }
2299 2297          return (__nss_buflen_default);
2300 2298  }
     2299 +
     2300 +void *
     2301 +_nss_XbyY_fini(nss_XbyY_args_t *args)
     2302 +{
     2303 +        if ((args->returnval == NULL) && (args->erange != 0))
     2304 +                errno = ERANGE;
     2305 +        return (args->returnval);
     2306 +}
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX