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

Diff for /src/usr.bin/ldap/ldapclient.c between version 1.9 and 1.10

version 1.9, 2018/11/07 13:58:51 version 1.10, 2018/11/27 12:04:57
Line 82 
Line 82 
 __dead void      usage(void);  __dead void      usage(void);
 int              ldapc_connect(struct ldapc *);  int              ldapc_connect(struct ldapc *);
 int              ldapc_search(struct ldapc *, struct ldapc_search *);  int              ldapc_search(struct ldapc *, struct ldapc_search *);
 int              ldapc_printattr(struct ldapc *, const char *, const char *);  int              ldapc_printattr(struct ldapc *, const char *,
                       const struct ber_octetstring *);
 void             ldapc_disconnect(struct ldapc *);  void             ldapc_disconnect(struct ldapc *);
 int              ldapc_parseurl(struct ldapc *, struct ldapc_search *,  int              ldapc_parseurl(struct ldapc *, struct ldapc_search *,
                     const char *);                      const char *);
Line 297 
Line 298 
         const char                      *errstr;          const char                      *errstr;
         const char                      *searchdn, *dn = NULL;          const char                      *searchdn, *dn = NULL;
         char                            *outkey;          char                            *outkey;
         char                            **outvalues;          struct aldap_stringset          *outvalues;
         int                              ret, i, code, fail = 0;          int                              ret, code, fail = 0;
           size_t                           i;
   
         if (ldap->ldap_flags & F_LDIF)          if (ldap->ldap_flags & F_LDIF)
                 printf("version: 1\n");                  printf("version: 1\n");
Line 359 
Line 361 
                         for (ret = aldap_first_attr(m, &outkey, &outvalues);                          for (ret = aldap_first_attr(m, &outkey, &outvalues);
                             ret != -1;                              ret != -1;
                             ret = aldap_next_attr(m, &outkey, &outvalues)) {                              ret = aldap_next_attr(m, &outkey, &outvalues)) {
                                 for (i = 0; outvalues != NULL &&                                  for (i = 0; i < outvalues->len; i++) {
                                     outvalues[i] != NULL; i++) {  
                                         if (ldapc_printattr(ldap, outkey,                                          if (ldapc_printattr(ldap, outkey,
                                             outvalues[i]) == -1) {                                              &(outvalues->str[i])) == -1) {
                                                 fail = 1;                                                  fail = 1;
                                                 break;                                                  break;
                                         }                                          }
Line 384 
Line 385 
 }  }
   
 int  int
 ldapc_printattr(struct ldapc *ldap, const char *key, const char *value)  ldapc_printattr(struct ldapc *ldap, const char *key,
       const struct ber_octetstring *value)
 {  {
         char                    *p = NULL, *out;          char                    *p = NULL, *out;
         const unsigned char     *cp;          const unsigned char     *cp;
         int                      encode;          int                      encode;
         size_t                   inlen, outlen, left;          size_t                   i, inlen, outlen, left;
   
         if (ldap->ldap_flags & F_LDIF) {          if (ldap->ldap_flags & F_LDIF) {
                 /* OpenLDAP encodes the userPassword by default */                  /* OpenLDAP encodes the userPassword by default */
Line 403 
Line 405 
                  * in SAFE-STRINGs. String value that do not match the                   * in SAFE-STRINGs. String value that do not match the
                  * criteria must be encoded as Base64.                   * criteria must be encoded as Base64.
                  */                   */
                 cp = (const unsigned char *)value;                  cp = (const unsigned char *)value->ostr_val;
                 /* !SAFE-INIT-CHAR: SAFE-CHAR minus %x20 %x3A %x3C */                  /* !SAFE-INIT-CHAR: SAFE-CHAR minus %x20 %x3A %x3C */
                 if (*cp == ' ' ||                  if (*cp == ' ' ||
                     *cp == ':' ||                      *cp == ':' ||
                     *cp == '<')                      *cp == '<')
                         encode = 1;                          encode = 1;
                 for (; encode == 0 &&*cp != '\0'; cp++) {                  for (i = 0; encode == 0 && i < value->ostr_len - 1; i++) {
                         /* !SAFE-CHAR %x01-09 / %x0B-0C / %x0E-7F */                          /* !SAFE-CHAR %x01-09 / %x0B-0C / %x0E-7F */
                         if (*cp > 127 ||                          if (cp[i] > 127 ||
                             *cp == '\0' ||                              cp[i] == '\0' ||
                             *cp == '\n' ||                              cp[i] == '\n' ||
                             *cp == '\r')                              cp[i] == '\r')
                                 encode = 1;                                  encode = 1;
                 }                  }
   
                 if (!encode) {                  if (!encode) {
                         if (asprintf(&p, "%s: %s", key, value) == -1) {                          if (asprintf(&p, "%s: %s", key,
                               (const char *)value->ostr_val) == -1) {
                                 log_warnx("asprintf");                                  log_warnx("asprintf");
                                 return (-1);                                  return (-1);
                         }                          }
                 } else {                  } else {
                         inlen = strlen(value);                          outlen = (((value->ostr_len + 2) / 3) * 4) + 1;
                         outlen = (((inlen + 2) / 3) * 4) + 1;  
   
                         if ((out = calloc(1, outlen)) == NULL ||                          if ((out = calloc(1, outlen)) == NULL ||
                             b64_ntop(value, inlen, out, outlen) == -1) {                              b64_ntop(value->ostr_val, value->ostr_len, out,
                               outlen) == -1) {
                                 log_warnx("Base64 encoding failed");                                  log_warnx("Base64 encoding failed");
                                 free(p);                                  free(p);
                                 return (-1);                                  return (-1);
Line 466 
Line 469 
                  * on all values no matter if they include non-printable                   * on all values no matter if they include non-printable
                  * characters.                   * characters.
                  */                   */
                 if (stravis(&p, value, VIS_SAFE|VIS_NL) == -1) {                  p = calloc(1, 4 * value->ostr_len + 1);
                   if (strvisx(p, value->ostr_val, value->ostr_len,
                       VIS_SAFE|VIS_NL) == -1) {
                         log_warn("visual encoding failed");                          log_warn("visual encoding failed");
                         return (-1);                          return (-1);
                 }                  }
   
                 printf("%s: %s\n", key, p);                  printf("%s: %s\n", key, p);
                   free(p);
         }          }
   
         free(p);          free(p);

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10