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


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

  23  * Copyright 2001-2003 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include <stdio.h>
  30 #include <string.h>
  31 #include <stdlib.h>
  32 #include <ctype.h>
  33 #include <fcntl.h>
  34 #include <unistd.h>
  35 #include <locale.h>
  36 
  37 #include "ldap_parse.h"
  38 #include "nis_parse_ldap_conf.h"


  39 
  40 /* other attribute functions */
  41 static char *getIndex(const char **s_cur, const char *end_s);
  42 static bool_t get_ttls(const char *s, const char *s_end,
  43     __nis_table_mapping_t *t_mapping);
  44 static __nis_object_dn_t *parse_object_dn(const char *s, const char *end);
  45 static int      parse_name_fields(const char *name_s, const char *name_s_end,
  46         __nis_table_mapping_t *t_mapping);
  47 static void get_mapping_rule(const char *s, int len,
  48     __nis_table_mapping_t *tbl, bool_t to_ldap);
  49 static bool_t get_deleteDisp(const char *s_begin, const char *s_end,
  50     __nis_object_dn_t *obj_dn);
  51 
  52 /* mapping rule functions */
  53 static const char *get_lhs(const char *s, const char *end_s,
  54     __nis_mapping_rlhs_t *lhs, __nis_mapping_item_type_t item_type);
  55 static const char *get_lhs_match(const char *s, const char *end_s,
  56     __nis_mapping_rlhs_t *lhs, __nis_mapping_item_type_t item_type);
  57 static const char *get_lhs_paren_item(const char *s, const char *end_s,
  58     __nis_mapping_rlhs_t *lhs, __nis_mapping_item_type_t item_type);


  76  *
  77  *      Adds the attribute value to __nis_table_mapping_t
  78  *      if the value is not yet set for the given database.
  79  *
  80  * RETURN VALUE:        0 on success, -1 on failure
  81  *
  82  * INPUT:               attribute number and value
  83  */
  84 
  85 int
  86 add_mapping_attribute(
  87         config_key              attrib_num,
  88         const char              *attrib_val,
  89         int                     attrib_len,
  90         __nis_table_mapping_t   **table_mapping)
  91 {
  92         const char              *s;
  93         const char              *attrib_end;
  94         const char              *db_id_end;
  95         const char              *begin_token;
  96         const char              *end_token;
  97         char                    *index_string;
  98         __nis_object_dn_t       *objectDN;
  99         __nis_table_mapping_t   *t_mapping;
 100         __nis_table_mapping_t   *t;
 101 
 102         bool_t                  new_mapping     = FALSE;
 103         int                             nm;
 104         char                    *tmp_dbId;
 105 
 106         attrib_end = attrib_val + attrib_len;
 107         for (s = attrib_val; s < attrib_end; s++)
 108                 if (*s == COLON_CHAR)
 109                         break;
 110 
 111         if (s == attrib_end || *attrib_val == COLON_CHAR) {
 112                 p_error = parse_unexpected_data_end_rule;
 113                 return (-1);
 114         }
 115 
 116         db_id_end = s;


 361  * FUNCTION:    add_ypdomains_attribute
 362  *
 363  * Adds the yp domains information to the __yp_domain_context_t
 364  * structure.
 365  *
 366  * RETURN:              0 on success, -1 on failure
 367  *
 368  * INPUT:               attribute number and value
 369  */
 370 
 371 int
 372 add_ypdomains_attribute(
 373         config_key              attrib_num,
 374         const char              *attrib_val,
 375         int                             attrib_len,
 376         __yp_domain_context_t   *ypDomains)
 377 {
 378         const char              *s;
 379         const char              *attrib_end;
 380         int                             numDomains = 0;
 381         int                     i;
 382         char                    *tmp_str;
 383         int                             ret = 0;
 384 
 385         attrib_end = attrib_val + attrib_len;
 386         for (s = attrib_val; s < attrib_end; s++) {
 387                 if (*s == COLON_CHAR) {
 388                         break;
 389                 }
 390         }
 391         while (s > attrib_val && is_whitespace(s[-1]))
 392                 s--;
 393 
 394         if (s == attrib_val) {
 395                 p_error = parse_unexpected_data_end_rule;
 396                 return (-1);
 397         }
 398 
 399         if (ypDomains == NULL) {
 400                 /*
 401                  * No point allocating. We cant return the resulting structure,
 402                  * so just return failure. Should not ever happen because we
 403                  * are always called with a pointer to the global ypDomains


1494                                         e->type = me_item;
1495                                         rhs->numElements = 1;
1496                                         rhs->element = e;
1497                                         return (s);
1498                                 } else if (t != comma_token) {
1499                                         p_error = parse_comma_expected_error;
1500                                         break;
1501                                 }
1502 
1503                                 begin_token = s;
1504                                 end_token = end_s;
1505                                 s = get_next_token(&begin_token, &end_token,
1506                                         &t);
1507                                 if (s == NULL || t != quoted_string_token) {
1508                                     p_error =
1509                                         parse_format_string_expected_error;
1510                                     break;
1511                                 }
1512 
1513                                 if (end_token == begin_token + 1 ||
1514                                     *begin_token == ESCAPE_CHAR &&
1515                                     end_token == begin_token + 2) {
1516                                         e->type = me_split;
1517                                         e->element.split.item = item;
1518                                         e->element.split.delim = *begin_token;
1519                                 } else {
1520                                         str = s_strndup(begin_token,
1521                                                 end_token - begin_token);
1522                                         if (str == NULL)
1523                                                 break;
1524                                         if (!get_mapping_format(str, &fmt,
1525                                             NULL, &n, FALSE))
1526                                                 break;
1527                                         free(str);
1528                                         str = NULL;
1529                                         if (n != 1) {
1530                                             p_error =
1531                                                 parse_bad_extract_format_spec;
1532                                             break;
1533                                         }
1534                                         e->type = me_extract;
1535                                         e->element.extract.item = item;


1636                         nSub++;
1637                 }
1638                 if (p_error != no_parse_error)
1639                         break;
1640 
1641                 begin_token = s;
1642                 end_token = end_s;
1643                 s = get_next_token(&begin_token, &end_token, &t);
1644                 if (s == NULL || t == no_token) {
1645                         p_error = parse_unexpected_data_end_rule;
1646                         break;
1647                 } else if (t == close_paren_token) {
1648                         doElide = FALSE;
1649                         elide = '\0';
1650                 } else if (t == comma_token) {
1651                         begin_token = s;
1652                         end_token = end_s;
1653                         s = get_next_token(&begin_token, &end_token, &t);
1654                         if (s != NULL && t == quoted_string_token &&
1655                                 (end_token == begin_token + 1 ||
1656                                     *begin_token == ESCAPE_CHAR &&
1657                                     end_token == begin_token + 2)) {
1658                                 if (numSubElements != 1 ||
1659                                     subElement->type == me_extract ||
1660                                     subElement->type == me_split) {
1661                                         p_error = parse_cannot_elide;
1662                                         break;
1663                                 }
1664                                 if (subElement->type == me_item &&
1665                                     !subElement->element.item.repeat) {
1666                                         p_error = parse_cannot_elide;
1667                                         break;
1668                                 }
1669                                 elide = *begin_token;
1670                                 doElide = TRUE;
1671 
1672                         } else {
1673                                 p_error = parse_bad_elide_char;
1674                                 break;
1675                         }
1676                         s = skip_token(s, end_s, close_paren_token);
1677                         if (s == NULL)


2050                                                         element.item.exItem =
2051                                                                 NULL;
2052                                                         break;
2053                                                 }
2054                                         }
2055                                 }
2056                                 return (s);
2057                         } else if (t != comma_token) {
2058                                 p_error = parse_comma_expected_error;
2059                                 break;
2060                         }
2061 
2062                         begin_token = s;
2063                         end_token = end_s;
2064                         s = get_next_token(&begin_token, &end_token, &t);
2065                         if (s == NULL || t != quoted_string_token) {
2066                                 p_error = parse_format_string_expected_error;
2067                                 break;
2068                         }
2069                         if (end_token == begin_token + 1 ||
2070                             *begin_token == ESCAPE_CHAR &&
2071                             end_token == begin_token + 2) {
2072                                         /* me_split */
2073                                 delim = (unsigned char)end_token[-1];
2074                                 s = skip_token(s, end_s, close_paren_token);
2075                                 if (s == NULL)
2076                                         break;
2077                                 subelement->element.split.item = item;
2078                                 subelement->element.split.delim = delim;
2079                                 subelement->type = me_split;
2080                                 return (s);
2081                         }
2082                         e_type = me_extract;
2083                 }
2084                 fmt_string = s_strndup(begin_token, end_token - begin_token);
2085                 if (fmt_string == NULL)
2086                         break;
2087                 if (!get_mapping_format(fmt_string, &base, &n, &numItems,
2088                     e_type == me_print)) {
2089                         free(fmt_string);
2090                         break;
2091                 }




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


  28 #include <stdio.h>
  29 #include <string.h>
  30 #include <stdlib.h>
  31 #include <ctype.h>
  32 #include <fcntl.h>
  33 #include <unistd.h>
  34 #include <locale.h>
  35 
  36 #include "ldap_parse.h"
  37 #include "nis_parse_ldap_conf.h"
  38 #include "nis_parse_ldap_yp_util.h"
  39 #include "nis_parse_ldap_util.h"
  40 
  41 /* other attribute functions */
  42 static char *getIndex(const char **s_cur, const char *end_s);
  43 static bool_t get_ttls(const char *s, const char *s_end,
  44     __nis_table_mapping_t *t_mapping);
  45 static __nis_object_dn_t *parse_object_dn(const char *s, const char *end);
  46 static int      parse_name_fields(const char *name_s, const char *name_s_end,
  47         __nis_table_mapping_t *t_mapping);
  48 static void get_mapping_rule(const char *s, int len,
  49     __nis_table_mapping_t *tbl, bool_t to_ldap);
  50 static bool_t get_deleteDisp(const char *s_begin, const char *s_end,
  51     __nis_object_dn_t *obj_dn);
  52 
  53 /* mapping rule functions */
  54 static const char *get_lhs(const char *s, const char *end_s,
  55     __nis_mapping_rlhs_t *lhs, __nis_mapping_item_type_t item_type);
  56 static const char *get_lhs_match(const char *s, const char *end_s,
  57     __nis_mapping_rlhs_t *lhs, __nis_mapping_item_type_t item_type);
  58 static const char *get_lhs_paren_item(const char *s, const char *end_s,
  59     __nis_mapping_rlhs_t *lhs, __nis_mapping_item_type_t item_type);


  77  *
  78  *      Adds the attribute value to __nis_table_mapping_t
  79  *      if the value is not yet set for the given database.
  80  *
  81  * RETURN VALUE:        0 on success, -1 on failure
  82  *
  83  * INPUT:               attribute number and value
  84  */
  85 
  86 int
  87 add_mapping_attribute(
  88         config_key              attrib_num,
  89         const char              *attrib_val,
  90         int                     attrib_len,
  91         __nis_table_mapping_t   **table_mapping)
  92 {
  93         const char              *s;
  94         const char              *attrib_end;
  95         const char              *db_id_end;
  96         const char              *begin_token;

  97         char                    *index_string;
  98         __nis_object_dn_t       *objectDN;
  99         __nis_table_mapping_t   *t_mapping;
 100         __nis_table_mapping_t   *t;
 101 
 102         bool_t                  new_mapping     = FALSE;
 103         int                             nm;
 104         char                    *tmp_dbId;
 105 
 106         attrib_end = attrib_val + attrib_len;
 107         for (s = attrib_val; s < attrib_end; s++)
 108                 if (*s == COLON_CHAR)
 109                         break;
 110 
 111         if (s == attrib_end || *attrib_val == COLON_CHAR) {
 112                 p_error = parse_unexpected_data_end_rule;
 113                 return (-1);
 114         }
 115 
 116         db_id_end = s;


 361  * FUNCTION:    add_ypdomains_attribute
 362  *
 363  * Adds the yp domains information to the __yp_domain_context_t
 364  * structure.
 365  *
 366  * RETURN:              0 on success, -1 on failure
 367  *
 368  * INPUT:               attribute number and value
 369  */
 370 
 371 int
 372 add_ypdomains_attribute(
 373         config_key              attrib_num,
 374         const char              *attrib_val,
 375         int                             attrib_len,
 376         __yp_domain_context_t   *ypDomains)
 377 {
 378         const char              *s;
 379         const char              *attrib_end;
 380         int                             numDomains = 0;



 381 
 382         attrib_end = attrib_val + attrib_len;
 383         for (s = attrib_val; s < attrib_end; s++) {
 384                 if (*s == COLON_CHAR) {
 385                         break;
 386                 }
 387         }
 388         while (s > attrib_val && is_whitespace(s[-1]))
 389                 s--;
 390 
 391         if (s == attrib_val) {
 392                 p_error = parse_unexpected_data_end_rule;
 393                 return (-1);
 394         }
 395 
 396         if (ypDomains == NULL) {
 397                 /*
 398                  * No point allocating. We cant return the resulting structure,
 399                  * so just return failure. Should not ever happen because we
 400                  * are always called with a pointer to the global ypDomains


1491                                         e->type = me_item;
1492                                         rhs->numElements = 1;
1493                                         rhs->element = e;
1494                                         return (s);
1495                                 } else if (t != comma_token) {
1496                                         p_error = parse_comma_expected_error;
1497                                         break;
1498                                 }
1499 
1500                                 begin_token = s;
1501                                 end_token = end_s;
1502                                 s = get_next_token(&begin_token, &end_token,
1503                                         &t);
1504                                 if (s == NULL || t != quoted_string_token) {
1505                                     p_error =
1506                                         parse_format_string_expected_error;
1507                                     break;
1508                                 }
1509 
1510                                 if (end_token == begin_token + 1 ||
1511                                     (*begin_token == ESCAPE_CHAR &&
1512                                     end_token == begin_token + 2)) {
1513                                         e->type = me_split;
1514                                         e->element.split.item = item;
1515                                         e->element.split.delim = *begin_token;
1516                                 } else {
1517                                         str = s_strndup(begin_token,
1518                                                 end_token - begin_token);
1519                                         if (str == NULL)
1520                                                 break;
1521                                         if (!get_mapping_format(str, &fmt,
1522                                             NULL, &n, FALSE))
1523                                                 break;
1524                                         free(str);
1525                                         str = NULL;
1526                                         if (n != 1) {
1527                                             p_error =
1528                                                 parse_bad_extract_format_spec;
1529                                             break;
1530                                         }
1531                                         e->type = me_extract;
1532                                         e->element.extract.item = item;


1633                         nSub++;
1634                 }
1635                 if (p_error != no_parse_error)
1636                         break;
1637 
1638                 begin_token = s;
1639                 end_token = end_s;
1640                 s = get_next_token(&begin_token, &end_token, &t);
1641                 if (s == NULL || t == no_token) {
1642                         p_error = parse_unexpected_data_end_rule;
1643                         break;
1644                 } else if (t == close_paren_token) {
1645                         doElide = FALSE;
1646                         elide = '\0';
1647                 } else if (t == comma_token) {
1648                         begin_token = s;
1649                         end_token = end_s;
1650                         s = get_next_token(&begin_token, &end_token, &t);
1651                         if (s != NULL && t == quoted_string_token &&
1652                             (end_token == begin_token + 1 ||
1653                             (*begin_token == ESCAPE_CHAR &&
1654                             end_token == begin_token + 2))) {
1655                                 if (numSubElements != 1 ||
1656                                     subElement->type == me_extract ||
1657                                     subElement->type == me_split) {
1658                                         p_error = parse_cannot_elide;
1659                                         break;
1660                                 }
1661                                 if (subElement->type == me_item &&
1662                                     !subElement->element.item.repeat) {
1663                                         p_error = parse_cannot_elide;
1664                                         break;
1665                                 }
1666                                 elide = *begin_token;
1667                                 doElide = TRUE;
1668 
1669                         } else {
1670                                 p_error = parse_bad_elide_char;
1671                                 break;
1672                         }
1673                         s = skip_token(s, end_s, close_paren_token);
1674                         if (s == NULL)


2047                                                         element.item.exItem =
2048                                                                 NULL;
2049                                                         break;
2050                                                 }
2051                                         }
2052                                 }
2053                                 return (s);
2054                         } else if (t != comma_token) {
2055                                 p_error = parse_comma_expected_error;
2056                                 break;
2057                         }
2058 
2059                         begin_token = s;
2060                         end_token = end_s;
2061                         s = get_next_token(&begin_token, &end_token, &t);
2062                         if (s == NULL || t != quoted_string_token) {
2063                                 p_error = parse_format_string_expected_error;
2064                                 break;
2065                         }
2066                         if (end_token == begin_token + 1 ||
2067                             (*begin_token == ESCAPE_CHAR &&
2068                             end_token == begin_token + 2)) {
2069                                         /* me_split */
2070                                 delim = (unsigned char)end_token[-1];
2071                                 s = skip_token(s, end_s, close_paren_token);
2072                                 if (s == NULL)
2073                                         break;
2074                                 subelement->element.split.item = item;
2075                                 subelement->element.split.delim = delim;
2076                                 subelement->type = me_split;
2077                                 return (s);
2078                         }
2079                         e_type = me_extract;
2080                 }
2081                 fmt_string = s_strndup(begin_token, end_token - begin_token);
2082                 if (fmt_string == NULL)
2083                         break;
2084                 if (!get_mapping_format(fmt_string, &base, &n, &numItems,
2085                     e_type == me_print)) {
2086                         free(fmt_string);
2087                         break;
2088                 }