[BACK]Return to aldap.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ldap

Diff for /src/usr.bin/ldap/aldap.c between version 1.5 and 1.6

version 1.5, 2018/08/12 22:04:09 version 1.6, 2018/11/27 12:04:57
Line 39 
Line 39 
                                     char *);                                      char *);
 static struct ber_element       *ldap_do_parse_search_filter(  static struct ber_element       *ldap_do_parse_search_filter(
                                     struct ber_element *, char **);                                      struct ber_element *, char **);
 char                            **aldap_get_stringset(struct ber_element *);  struct aldap_stringset          *aldap_get_stringset(struct ber_element *);
 char                            *utoa(char *);  char                            *utoa(char *);
 static int                       isu8cont(unsigned char);  static int                       isu8cont(unsigned char);
 char                            *parseval(char *, size_t);  char                            *parseval(char *, size_t);
Line 522 
Line 522 
         return utoa(dn);          return utoa(dn);
 }  }
   
 char **  struct aldap_stringset *
 aldap_get_references(struct aldap_message *msg)  aldap_get_references(struct aldap_message *msg)
 {  {
         if (msg->references == NULL)          if (msg->references == NULL)
Line 576 
Line 576 
 }  }
   
 int  int
 aldap_first_attr(struct aldap_message *msg, char **outkey, char ***outvalues)  aldap_first_attr(struct aldap_message *msg, char **outkey,
       struct aldap_stringset **outvalues)
 {  {
         struct ber_element *b, *c;          struct ber_element *b, *c;
         char *key;          char *key;
         char **ret;          struct aldap_stringset *ret;
   
         if (msg->body.search.attrs == NULL)          if (msg->body.search.attrs == NULL)
                 goto fail;                  goto fail;
Line 605 
Line 606 
 }  }
   
 int  int
 aldap_next_attr(struct aldap_message *msg, char **outkey, char ***outvalues)  aldap_next_attr(struct aldap_message *msg, char **outkey,
       struct aldap_stringset **outvalues)
 {  {
         struct ber_element *a, *b;          struct ber_element *a, *b;
         char *key;          char *key;
         char **ret;          struct aldap_stringset *ret;
   
         if (msg->body.search.iter == NULL)          if (msg->body.search.iter == NULL)
                 goto notfound;                  goto notfound;
Line 640 
Line 642 
 }  }
   
 int  int
 aldap_match_attr(struct aldap_message *msg, char *inkey, char ***outvalues)  aldap_match_attr(struct aldap_message *msg, char *inkey,
       struct aldap_stringset **outvalues)
 {  {
         struct ber_element *a, *b;          struct ber_element *a, *b;
         char *descr = NULL;          char *descr = NULL;
         char **ret;          struct aldap_stringset *ret;
   
         if (msg->body.search.attrs == NULL)          if (msg->body.search.attrs == NULL)
                 goto fail;                  goto fail;
Line 677 
Line 680 
 }  }
   
 int  int
 aldap_free_attr(char **values)  aldap_free_attr(struct aldap_stringset *values)
 {  {
         int i;  
   
         if (values == NULL)          if (values == NULL)
                 return -1;                  return -1;
   
         for (i = 0; values[i] != NULL; i++)          free(values->str);
                 free(values[i]);  
   
         free(values);          free(values);
   
         return (1);          return (1);
Line 836 
Line 835 
  * internal functions   * internal functions
  */   */
   
 char **  struct aldap_stringset *
 aldap_get_stringset(struct ber_element *elm)  aldap_get_stringset(struct ber_element *elm)
 {  {
         struct ber_element *a;          struct ber_element *a;
         int i;          int i;
         char **ret;          struct aldap_stringset *ret;
         char *s;  
   
         if (elm->be_type != BER_TYPE_OCTETSTRING)          if (elm->be_type != BER_TYPE_OCTETSTRING)
                 return NULL;                  return NULL;
   
         for (a = elm, i = 1; i > 0 && a != NULL && a->be_type ==          if ((ret = malloc(sizeof(*ret))) == NULL)
             BER_TYPE_OCTETSTRING; a = a->be_next, i++)                  return NULL;
           for (a = elm, ret->len = 0; a != NULL && a->be_type ==
               BER_TYPE_OCTETSTRING; a = a->be_next, ret->len++)
                 ;                  ;
         if (i == 1)          if (ret->len == 0) {
                   free(ret);
                 return NULL;                  return NULL;
           }
   
         if ((ret = calloc(i + 1, sizeof(char *))) == NULL)          if ((ret->str = reallocarray(NULL, ret->len,
               sizeof(*(ret->str)))) == NULL) {
                   free(ret);
                 return NULL;                  return NULL;
           }
   
         for (a = elm, i = 0; a != NULL && a->be_type == BER_TYPE_OCTETSTRING;          for (a = elm, i = 0; a != NULL && a->be_type == BER_TYPE_OCTETSTRING;
             a = a->be_next, i++) {              a = a->be_next, i++)
                   (void) ber_get_ostring(a, &(ret->str[i]));
                 ber_get_string(a, &s);  
                 ret[i] = utoa(s);  
         }  
         ret[i + 1] = NULL;  
   
         return ret;          return ret;
 }  }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6