Print this page
5910 libnisdb won't build with modern GCC


   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*

  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 
  27 #include <strings.h>
  28 #include <string.h>
  29 #include <lber.h>
  30 #include <ldap.h>
  31 
  32 #include "db_item_c.h"
  33 
  34 #include "nisdb_mt.h"
  35 
  36 #include "ldap_util.h"
  37 #include "ldap_structs.h"
  38 #include "ldap_val.h"
  39 #include "ldap_ruleval.h"
  40 #include "ldap_op.h"
  41 #include "ldap_nisdbquery.h"
  42 #include "ldap_attr.h"
  43 #include "ldap_xdr.h"

  44 
  45 
  46 item *
  47 buildItem(int len, void *value) {
  48         char    *myself = "buildItem";
  49         item    *i = am(myself, sizeof (*i));
  50         int     mlen = len;
  51 
  52         if (i == 0)
  53                 return (0);
  54 
  55         /*
  56          * To this function, a NULL value, or a length less than or equal
  57          * zero means an item with no value. Hence, buildItem(0, 0) is
  58          * _not_ the right way to create index_value == 0 to indicate
  59          * deletion.
  60          */
  61         if (value == 0 || len <= 0) {
  62                 i->itemvalue.itemvalue_len = 0;
  63                 i->itemvalue.itemvalue_val = 0;


 207 
 208 /*
 209  * Given an array index[0..num-1] of pointers to strings of the form
 210  * "name=value", create the corresponding db_queries. "name=" indicates
 211  * deletion, which results in a db_query component where index_value == 0.
 212  *
 213  * The __nis_table_mapping_t structure is used to translate column
 214  * names to indices.
 215  *
 216  * If 'rvP' is non-NULL, the searchable columns from the 'index'
 217  * name/value pairs are used to retrieve copies of the corresponding NIS+
 218  * entries, and '*rvP' is initialized with the current entry values
 219  * and object attributes. Names/values supplied in 'index' override
 220  * those from existing NIS+ entries.
 221  */
 222 db_query **
 223 createQuery(int num, char **index, __nis_table_mapping_t *t,
 224                 __nis_rule_value_t **rvP, int *numVals) {
 225         db_query                **q;
 226         db_qcomp                *qc;
 227         int                     i, j, n, a, nv, niv, stat, sinum;
 228         __nis_rule_value_t      *rvq;
 229         __nis_buffer_t          b = {0, 0};
 230         char                    *table = 0;
 231         char                    *myself = "createQuery";
 232 
 233         rvq = initRuleValue(1, 0);
 234         if (rvq == 0)
 235                 return (0);
 236 
 237         if (numVals == 0)
 238                 numVals = &nv;
 239         *numVals = 0;
 240 
 241         if (rvP != 0) {
 242                 /*
 243                  * Try to obtain a copy of the table object, in order to
 244                  * determine the searchable columns. A failure isn't
 245                  * necessarily fatal; we just try to compose the entire
 246                  * LDAP data from the col=val pairs.
 247                  */
 248                 table = fullObjName(F, t->objName);
 249                 if (table == 0) {
 250                         logmsg(MSG_NOTIMECHECK, LOG_ERR,
 251                                 "%s: Error converting \"%s\" to FQ object name",
 252                                 myself, NIL(t->objName));
 253                         freeRuleValue(rvq, 1);
 254                         return (0);
 255                 }
 256         }
 257 
 258         /* Create a rule-value from the col=val pairs */
 259         for (n = 0; n < num; n++) {
 260                 char    *name;
 261                 char    *value;
 262 
 263                 if ((value = strchr(index[n], '=')) == 0) {
 264                         logmsg(MSG_NOTIMECHECK, LOG_WARNING,
 265                                 "%s: no '=' in \"%s\"",
 266                                 myself, index[n]);
 267                         continue;
 268                 }
 269 
 270                 *value = '\0';
 271                 value++;
 272 
 273                 for (a = 0; a < t->numColumns; a++) {
 274                         if (strcmp(index[n], t->column[a]) == 0) {
 275                                 int             i, len = slen(value)+1;
 276 
 277                                 /* Add col=val pair to 'rvq' */
 278                                 if (addSCol2RuleValue(index[n], value, rvq)) {
 279                                         freeRuleValue(rvq, 1);
 280                                         sfree(table);
 281                                         return (0);
 282                                 }
 283 
 284                                 break;
 285                         }
 286                 }
 287                 if (a >= t->numColumns) {
 288                         logmsg(MSG_NOTIMECHECK, LOG_WARNING,
 289                                 "%s: Ignoring unknown column \"%s\"",
 290                                 myself, NIL(index[n]));
 291                 }
 292         }
 293 
 294         /*
 295          * Find out if any of the columns specified via the 'index'


 675         free(q);
 676         if (objAttr != 0) {
 677                 sfree(*objAttr);
 678                 *objAttr = attr;
 679         }
 680 
 681         *numQueries = nn;
 682 
 683         return (new);
 684 }
 685 
 686 db_query **
 687 createNisPlusEntry(__nis_table_mapping_t *t, __nis_rule_value_t *rv,
 688                         db_query *qin, __nis_obj_attr_t ***objAttr,
 689                         int *numQueries) {
 690         db_query                **query = 0;
 691         int                     r, i, j, ir;
 692         __nis_value_t           *rval, *lval;
 693         __nis_mapping_item_t    *litem;
 694         int                     numItems;
 695         int                     nq, iqc;
 696         __nis_obj_attr_t        **attr = 0;
 697         char                    **dn = 0;
 698         int                     numDN = 0;
 699         char                    *myself = "createNisPlusEntry";
 700 
 701         if (t == 0 || t->objectDN == 0 || rv == 0)
 702                 return (0);
 703 
 704         /* Establish default, per-thread, search base */
 705         __nisdb_get_tsd()->searchBase = t->objectDN->read.base;
 706 
 707         for (r = 0, nq = 0; r < t->numRulesFromLDAP; r++) {
 708                 int                     nrq, ntq, err;
 709                 db_query                **newq;
 710                 __nis_obj_attr_t        **newattr;
 711 
 712                 rval = buildRvalue(&t->ruleFromLDAP[r]->rhs,
 713                         mit_ldap, rv, NULL);
 714                 if (rval == 0)
 715                         continue;




   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2015 Gary Mills
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 
  28 #include <strings.h>
  29 #include <string.h>
  30 #include <lber.h>
  31 #include <ldap.h>
  32 
  33 #include "db_item_c.h"
  34 
  35 #include "nisdb_mt.h"
  36 
  37 #include "ldap_util.h"
  38 #include "ldap_structs.h"
  39 #include "ldap_val.h"
  40 #include "ldap_ruleval.h"
  41 #include "ldap_op.h"
  42 #include "ldap_nisdbquery.h"
  43 #include "ldap_attr.h"
  44 #include "ldap_xdr.h"
  45 #include "ldap_ldap.h"
  46 
  47 
  48 item *
  49 buildItem(int len, void *value) {
  50         char    *myself = "buildItem";
  51         item    *i = am(myself, sizeof (*i));
  52         int     mlen = len;
  53 
  54         if (i == 0)
  55                 return (0);
  56 
  57         /*
  58          * To this function, a NULL value, or a length less than or equal
  59          * zero means an item with no value. Hence, buildItem(0, 0) is
  60          * _not_ the right way to create index_value == 0 to indicate
  61          * deletion.
  62          */
  63         if (value == 0 || len <= 0) {
  64                 i->itemvalue.itemvalue_len = 0;
  65                 i->itemvalue.itemvalue_val = 0;


 209 
 210 /*
 211  * Given an array index[0..num-1] of pointers to strings of the form
 212  * "name=value", create the corresponding db_queries. "name=" indicates
 213  * deletion, which results in a db_query component where index_value == 0.
 214  *
 215  * The __nis_table_mapping_t structure is used to translate column
 216  * names to indices.
 217  *
 218  * If 'rvP' is non-NULL, the searchable columns from the 'index'
 219  * name/value pairs are used to retrieve copies of the corresponding NIS+
 220  * entries, and '*rvP' is initialized with the current entry values
 221  * and object attributes. Names/values supplied in 'index' override
 222  * those from existing NIS+ entries.
 223  */
 224 db_query **
 225 createQuery(int num, char **index, __nis_table_mapping_t *t,
 226                 __nis_rule_value_t **rvP, int *numVals) {
 227         db_query                **q;
 228         db_qcomp                *qc;
 229         int                     i, j, n, a, nv, niv;
 230         __nis_rule_value_t      *rvq;
 231         __nis_buffer_t          b = {0, 0};
 232         char                    *table = 0;
 233         char                    *myself = "createQuery";
 234 
 235         rvq = initRuleValue(1, 0);
 236         if (rvq == 0)
 237                 return (0);
 238 
 239         if (numVals == 0)
 240                 numVals = &nv;
 241         *numVals = 0;
 242 
 243         if (rvP != 0) {
 244                 /*
 245                  * Try to obtain a copy of the table object, in order to
 246                  * determine the searchable columns. A failure isn't
 247                  * necessarily fatal; we just try to compose the entire
 248                  * LDAP data from the col=val pairs.
 249                  */
 250                 table = fullObjName(F, t->objName);
 251                 if (table == 0) {
 252                         logmsg(MSG_NOTIMECHECK, LOG_ERR,
 253                                 "%s: Error converting \"%s\" to FQ object name",
 254                                 myself, NIL(t->objName));
 255                         freeRuleValue(rvq, 1);
 256                         return (0);
 257                 }
 258         }
 259 
 260         /* Create a rule-value from the col=val pairs */
 261         for (n = 0; n < num; n++) {

 262                 char    *value;
 263 
 264                 if ((value = strchr(index[n], '=')) == 0) {
 265                         logmsg(MSG_NOTIMECHECK, LOG_WARNING,
 266                                 "%s: no '=' in \"%s\"",
 267                                 myself, index[n]);
 268                         continue;
 269                 }
 270 
 271                 *value = '\0';
 272                 value++;
 273 
 274                 for (a = 0; a < t->numColumns; a++) {
 275                         if (strcmp(index[n], t->column[a]) == 0) {

 276 
 277                                 /* Add col=val pair to 'rvq' */
 278                                 if (addSCol2RuleValue(index[n], value, rvq)) {
 279                                         freeRuleValue(rvq, 1);
 280                                         sfree(table);
 281                                         return (0);
 282                                 }
 283 
 284                                 break;
 285                         }
 286                 }
 287                 if (a >= t->numColumns) {
 288                         logmsg(MSG_NOTIMECHECK, LOG_WARNING,
 289                                 "%s: Ignoring unknown column \"%s\"",
 290                                 myself, NIL(index[n]));
 291                 }
 292         }
 293 
 294         /*
 295          * Find out if any of the columns specified via the 'index'


 675         free(q);
 676         if (objAttr != 0) {
 677                 sfree(*objAttr);
 678                 *objAttr = attr;
 679         }
 680 
 681         *numQueries = nn;
 682 
 683         return (new);
 684 }
 685 
 686 db_query **
 687 createNisPlusEntry(__nis_table_mapping_t *t, __nis_rule_value_t *rv,
 688                         db_query *qin, __nis_obj_attr_t ***objAttr,
 689                         int *numQueries) {
 690         db_query                **query = 0;
 691         int                     r, i, j, ir;
 692         __nis_value_t           *rval, *lval;
 693         __nis_mapping_item_t    *litem;
 694         int                     numItems;
 695         int                     nq;
 696         __nis_obj_attr_t        **attr = 0;
 697         char                    **dn = 0;
 698         int                     numDN = 0;
 699         char                    *myself = "createNisPlusEntry";
 700 
 701         if (t == 0 || t->objectDN == 0 || rv == 0)
 702                 return (0);
 703 
 704         /* Establish default, per-thread, search base */
 705         __nisdb_get_tsd()->searchBase = t->objectDN->read.base;
 706 
 707         for (r = 0, nq = 0; r < t->numRulesFromLDAP; r++) {
 708                 int                     nrq, ntq, err;
 709                 db_query                **newq;
 710                 __nis_obj_attr_t        **newattr;
 711 
 712                 rval = buildRvalue(&t->ruleFromLDAP[r]->rhs,
 713                         mit_ldap, rv, NULL);
 714                 if (rval == 0)
 715                         continue;