Open
Bug 413528
Opened 17 years ago
Updated 17 years ago
values being with '<' are treated as file URLs
Categories
(Directory :: LDAP C SDK, defect)
Tracking
(Not tracked)
UNCONFIRMED
People
(Reporter: mark.reynolds, Assigned: mcs)
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11
Build Identifier: mozldap-6.0.5
First we need to look at the RFR for value specs:
"value-spec" is defined as follows by RFC2849.
value-spec = ":" ( FILL 0*1(SAFE-STRING) /
":" FILL (BASE64-STRING) /
"<" FILL url)
Therefore, "value-spec" becomes only the following three patterns.
attribute: SAFE-STRING
attribute:: BASE64-STRING
attribute:< url
If you add a value like: "sn: <1234567", it gets incorrectly treated like a file URL. Now if the value was: "sn:< 123345" then it should be treated like a file URL(then an unsupported file URL error ,etc)
Reproducible: Always
Steps to Reproduce:
1. Create a LDIF like (e.g. add.ldif):
-----------------------------------------
version: 1
dn: uid=mark,o=test.com
uid: mark
givenName: mark
cn: mark reynolds
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetorgperson
sn: <1234567
-----------------------------------------
-> "version: 1" is necessary
2. Use ldapmodify: ldapmodify -D "cn=directory manager" -w password -a -f add.ldif
You will get an error:
ldapmodify: unsupported URL "1234567"; use a file:// URL instead.
Actual Results:
# ldapmodify -D "cn=directory manager" -w password -a -f add.ldif
ldapmodify: unsupported URL "1234567"; use a file:// URL instead.
#
Expected Results:
The modify should succeed
I have a fix for this, but I'm not sure what to do next...
Assignee | ||
Comment 1•17 years ago
|
||
Please attach your patch here.
Reporter | ||
Comment 2•17 years ago
|
||
In this fix, instead of just checking for '<' as the beginning value to determine if the value is file URL, we need look for ':<' when processing the ldif line and then just pass a flag up through the calls to the appropriate function. Because "sn: <blah", even "sn: <file:///", are NOT file URLs according to the RFC, it has to be "sn:< file://", just like a base 64 values start like "sn:: sd8f7sd8f7=" - not "sn: :3sdf897g="
Here are the diffs:
Index: fileurl.h
===================================================================
RCS file: /m/src/mozilla/directory/c-sdk/ldap/clients/tools/fileurl.h,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 fileurl.h
*** fileurl.h 12 Mar 2002 18:01:31 -0000 1.1.1.1
--- fileurl.h 22 Jan 2008 21:55:52 -0000
***************
*** 64,70 ****
*/
int ldaptool_berval_from_ldif_value( const char *value, int vlen,
struct berval *bvp, int recognize_url_syntax, int always_try_file,
! int reporterrs );
/*
--- 64,70 ----
*/
int ldaptool_berval_from_ldif_value( const char *value, int vlen,
struct berval *bvp, int recognize_url_syntax, int always_try_file,
! int reporterrs, int fileURL );
/*
Index: fileurl.c
===================================================================
RCS file: /m/src/mozilla/directory/c-sdk/ldap/clients/tools/fileurl.c,v
retrieving revision 1.1.1.1.2.4
diff -c -r1.1.1.1.2.4 fileurl.c
*** fileurl.c 28 May 2003 20:03:21 -0000 1.1.1.1.2.4
--- fileurl.c 23 Jan 2008 20:43:49 -0000
***************
*** 217,226 ****
int
ldaptool_berval_from_ldif_value( const char *value, int vlen,
struct berval *bvp, int recognize_url_syntax, int always_try_file,
! int reporterrs )
{
int rc = LDAPTOOL_FILEURL_SUCCESS; /* optimistic */
- const char *url = NULL;
struct stat fstats;
/* recognize "attr :< url" syntax if LDIF version is >= 1 */
--- 217,225 ----
int
ldaptool_berval_from_ldif_value( const char *value, int vlen,
struct berval *bvp, int recognize_url_syntax, int always_try_file,
! int reporterrs, int fileURL )
{
int rc = LDAPTOOL_FILEURL_SUCCESS; /* optimistic */
struct stat fstats;
/* recognize "attr :< url" syntax if LDIF version is >= 1 */
***************
*** 232,271 ****
}
#endif
! if ( recognize_url_syntax && *value == '<' ) {
! for ( url = value + 1; isspace( *url ); ++url ) {
! ; /* NULL */
! }
!
! if (strlen(url) > 7 && strncasecmp(url, "file://", 7) != 0) {
! /*
! * We only support file:// URLs for now.
! */
! url = NULL;
! }
! }
!
! if ( NULL != url ) {
char *path;
! rc = ldaptool_fileurl2path( url, &path );
switch( rc ) {
case LDAPTOOL_FILEURL_NOTAFILEURL:
if ( reporterrs ) fprintf( stderr, "%s: unsupported URL \"%s\";"
! " use a file:// URL instead.\n", ldaptool_progname, url );
break;
case LDAPTOOL_FILEURL_MISSINGPATH:
if ( reporterrs ) fprintf( stderr,
"%s: unable to process URL \"%s\" --"
! " missing path.\n", ldaptool_progname, url );
break;
case LDAPTOOL_FILEURL_NONLOCAL:
if ( reporterrs ) fprintf( stderr,
"%s: unable to process URL \"%s\" -- only
"
" local file:// URLs are supported.\n",
! ldaptool_progname, url );
break;
case LDAPTOOL_FILEURL_NOMEMORY:
--- 231,257 ----
}
#endif
! if ( recognize_url_syntax && fileURL ) {
char *path;
! rc = ldaptool_fileurl2path( value, &path );
switch( rc ) {
case LDAPTOOL_FILEURL_NOTAFILEURL:
if ( reporterrs ) fprintf( stderr, "%s: unsupported URL \"%s\";"
! " use a file:// URL instead.\n", ldaptool_progname, value );
break;
case LDAPTOOL_FILEURL_MISSINGPATH:
if ( reporterrs ) fprintf( stderr,
"%s: unable to process URL \"%s\" --"
! " missing path.\n", ldaptool_progname, value );
break;
case LDAPTOOL_FILEURL_NONLOCAL:
if ( reporterrs ) fprintf( stderr,
"%s: unable to process URL \"%s\" -- only
"
" local file:// URLs are supported.\n",
! ldaptool_progname, value );
break;
case LDAPTOOL_FILEURL_NOMEMORY:
***************
*** 289,295 ****
default:
if ( reporterrs ) fprintf( stderr,
"%s: unable to process URL \"%s\""
! " -- unknown error\n", ldaptool_progname, url );
}
} else if ( always_try_file && (stat( value, &fstats ) == 0) &&
!(fstats.st_mode & S_IFDIR)) { /* get value from file */
--- 275,281 ----
default:
if ( reporterrs ) fprintf( stderr,
"%s: unable to process URL \"%s\""
! " -- unknown error\n", ldaptool_progname, value );
}
} else if ( always_try_file && (stat( value, &fstats ) == 0) &&
!(fstats.st_mode & S_IFDIR)) { /* get value from file */
Index: common.c
===================================================================
RCS file: /m/src/mozilla/directory/c-sdk/ldap/clients/tools/common.c,v
retrieving revision 1.1.1.1.2.12
diff -c -r1.1.1.1.2.12 common.c
*** common.c 28 May 2003 20:03:21 -0000 1.1.1.1.2.12
--- common.c 22 Jan 2008 21:59:29 -0000
***************
*** 596,602 ****
vlen, &(ldctrl->ldctl_value),
1 /* recognize file URLs */,
0 /* always try file */,
! 1 /* report errors */ );
if ((rc = ldaptool_fileurlerr2ldaperr( rc )) != LDAP_SUCCESS) {
fprintf( stderr, "Unable to parse %s\n", ctrl_value);
return (-1);
--- 596,603 ----
vlen, &(ldctrl->ldctl_value),
1 /* recognize file URLs */,
0 /* always try file */,
! 1 /* report errors */,
! 0 /* file URL*/ );
if ((rc = ldaptool_fileurlerr2ldaperr( rc )) != LDAP_SUCCESS) {
fprintf( stderr, "Unable to parse %s\n", ctrl_value);
return (-1);
Index: ldapmodify.c
===================================================================
RCS file: /m/src/mozilla/directory/c-sdk/ldap/clients/tools/ldapmodify.c,v
retrieving revision 1.1.1.1.2.3
diff -c -r1.1.1.1.2.3 ldapmodify.c
*** ldapmodify.c 16 Aug 2004 14:18:39 -0000 1.1.1.1.2.3
--- ldapmodify.c 23 Jan 2008 20:47:01 -0000
***************
*** 66,72 ****
static int process_ldapmod_rec( char *rbuf );
static int process_ldif_rec( char *rbuf );
static void addmodifyop( LDAPMod ***pmodsp, int modop, char *attr,
! char *value, int vlen );
static int domodify( char *dn, LDAPMod **pmods, int newentry );
static int dodelete( char *dn );
static int dorename( char *dn, char *newrdn, char *newparent,
--- 66,72 ----
static int process_ldapmod_rec( char *rbuf );
static int process_ldif_rec( char *rbuf );
static void addmodifyop( LDAPMod ***pmodsp, int modop, char *attr,
! char *value, int vlen, int fileURL );
static int domodify( char *dn, LDAPMod **pmods, int newentry );
static int dodelete( char *dn );
static int dorename( char *dn, char *newrdn, char *newparent,
***************
*** 312,317 ****
--- 312,318 ----
int expect_deleteoldrdn, expect_newparent, rename, moddn;
int deleteoldrdn, saw_replica, use_record, new_entry, delete_entry;
int got_all, got_value;
+ int fileURL;
LDAPMod **pmods;
new_entry = newval;
***************
*** 326,331 ****
--- 327,334 ----
while ( rc == 0 && ( line = ldif_getline( &rbuf )) != NULL ) {
++linenum;
+ fileURL = 0;
+
if ( expect_sep && strcasecmp( line, T_MODSEPSTR ) == 0 ) {
expect_sep = 0;
expect_modop = 1;
***************
*** 334,347 ****
but we didn't get a value from the last modify
then we have to fill pmods with an empty value*/
if (modop == LDAP_MOD_REPLACE && !got_value){
! addmodifyop( &pmods, modop, value, NULL, 0);
}
got_value = 0;
continue;
}
! if ( ldif_parse_line( line, &type, &value, &vlen ) < 0 ) {
fprintf( stderr, "%s: invalid format (line %d of entry: %s)\n",
ldaptool_progname, linenum, dn == NULL ? "" : dn );
fprintf( stderr, "%s: line contents: (%s)\n",
--- 337,350 ----
but we didn't get a value from the last modify
then we have to fill pmods with an empty value*/
if (modop == LDAP_MOD_REPLACE && !got_value){
! addmodifyop( &pmods, modop, value, NULL, 0 ,0 );
}
got_value = 0;
continue;
}
! if ( ldif_parse_line( line, &type, &value, &vlen, &fileURL ) < 0 ) {
fprintf( stderr, "%s: invalid format (line %d of entry: %s)\n",
ldaptool_progname, linenum, dn == NULL ? "" : dn );
fprintf( stderr, "%s: line contents: (%s)\n",
***************
*** 403,426 ****
if ( expect_chgtype_or_control ) {
expect_chgtype_or_control = 0;
if ( !use_record && saw_replica ) {
! printf( "%s: skipping change record for entry: %s\n\t(LDAP host/port does not match replica: lines)\n",
ldaptool_progname, dn );
! free( dn );
! return( 0 );
}
if ( strcasecmp( type, "control" ) == 0 ) {
! value = strdup_and_trim( value );
! if (ldaptool_parse_ctrl_arg(value, ' ', &ctrl_oid,
! &ctrl_criticality, &ctrl_value, &vlen)) {
usage();
! }
ldctrl = calloc(1,sizeof(LDAPControl));
if (ctrl_value) {
! rc = ldaptool_berval_from_ldif_value( ctrl_value, vlen,
! &(ldctrl->ldctl_value),
! 1 /* recognize file URLs */, 0 /* always try file */,
! 1 /* report errors */ );
if ((rc = ldaptool_fileurlerr2ldaperr( rc )) != LDAP_SUCCESS) {
fprintf( stderr, "Unable to parse %s\n", ctrl_value);
usage();
--- 406,429 ----
if ( expect_chgtype_or_control ) {
expect_chgtype_or_control = 0;
if ( !use_record && saw_replica ) {
! printf( "%s: skipping change record for entry: %s\n\t(LDAP host/port does not match replica: lines)\n",
ldaptool_progname, dn );
! free( dn );
! return( 0 );
}
if ( strcasecmp( type, "control" ) == 0 ) {
! value = strdup_and_trim( value );
! if (ldaptool_parse_ctrl_arg(value, ' ', &ctrl_oid,
! &ctrl_criticality, &ctrl_value, &vlen)) {
usage();
! }
!
ldctrl = calloc(1,sizeof(LDAPControl));
if (ctrl_value) {
!
! rc = ldaptool_berval_from_ldif_value( ctrl_value, vlen, &(ldctrl->ldctl_value),
! 1 /* recognize file URLs */, 0 /* always try file */, 1 /* report errors */, 0 );
if ((rc = ldaptool_fileurlerr2ldaperr( rc )) != LDAP_SUCCESS) {
fprintf( stderr, "Unable to parse %s\n", ctrl_value);
usage();
***************
*** 485,491 ****
continue;
} else if ( strcasecmp( type, T_MODOPDELETESTR ) == 0 ) {
modop = LDAP_MOD_DELETE;
! addmodifyop( &pmods, modop, value, NULL, 0 );
continue;
} else { /*Bug 27479. Remove default add operation*/
fprintf(stderr, "%s: Invalid parameter \"%s\" specified for changetype modify (line %d of entry %s)\n",
--- 489,495 ----
continue;
} else if ( strcasecmp( type, T_MODOPDELETESTR ) == 0 ) {
modop = LDAP_MOD_DELETE;
! addmodifyop( &pmods, modop, value, NULL, 0, fileURL );
continue;
} else { /*Bug 27479. Remove default add operation*/
fprintf(stderr, "%s: Invalid parameter \"%s\" specified for changetype modify (line %d of entry %s)\n",
***************
*** 565,571 ****
rc = LDAP_PARAM_ERROR;
got_all = 1;
} else {
! addmodifyop( &pmods, modop, type, value, vlen );
/*There was a value to replace*/
got_value = 1;
--- 569,575 ----
rc = LDAP_PARAM_ERROR;
got_all = 1;
} else {
! addmodifyop( &pmods, modop, type, value, vlen, fileURL );
/*There was a value to replace*/
got_value = 1;
***************
*** 585,591 ****
attribute to replace, so we alloc
an empty pmods*/
if (modop == LDAP_MOD_REPLACE && !got_value && expect_sep){
! addmodifyop( &pmods, modop, value, NULL, 0);
}/*End Patch*/
--- 589,595 ----
attribute to replace, so we alloc
an empty pmods*/
if (modop == LDAP_MOD_REPLACE && !got_value && expect_sep){
! addmodifyop( &pmods, modop, value, NULL, 0, fileURL);
}/*End Patch*/
***************
*** 699,705 ****
}
addmodifyop( &pmods, modop, attr, value,
! ( value == NULL ) ? 0 : strlen( value ));
}
}
--- 703,709 ----
}
addmodifyop( &pmods, modop, attr, value,
! ( value == NULL ) ? 0 : strlen( value ), 0);
}
}
***************
*** 726,732 ****
static void
! addmodifyop( LDAPMod ***pmodsp, int modop, char *attr, char *value, int vlen )
{
LDAPMod **pmods;
int i, j, rc;
--- 730,736 ----
static void
! addmodifyop( LDAPMod ***pmodsp, int modop, char *attr, char *value, int vlen, int fileURL )
{
LDAPMod **pmods;
int i, j, rc;
***************
*** 793,799 ****
#endif
rc = ldaptool_berval_from_ldif_value( value, vlen, bvp,
( ldif_version >= LDIF_VERSION_ONE ), valsfromfiles,
! 1 /* report errors */ );
if ( rc != LDAPTOOL_FILEURL_SUCCESS ) {
exit( ldaptool_fileurlerr2ldaperr( rc ));
}
--- 797,803 ----
#endif
rc = ldaptool_berval_from_ldif_value( value, vlen, bvp,
( ldif_version >= LDIF_VERSION_ONE ), valsfromfiles,
! 1 /* report errors */, fileURL );
if ( rc != LDAPTOOL_FILEURL_SUCCESS ) {
exit( ldaptool_fileurlerr2ldaperr( rc ));
}
Index: ldapcompare.c
===================================================================
RCS file: /m/src/mozilla/directory/c-sdk/ldap/clients/tools/ldapcompare.c,v
retrieving revision 1.1.1.1.2.3
diff -c -r1.1.1.1.2.3 ldapcompare.c
*** ldapcompare.c 16 Aug 2004 14:18:39 -0000 1.1.1.1.2.3
--- ldapcompare.c 22 Jan 2008 22:07:23 -0000
***************
*** 207,221 ****
typeval2berval( char *typeval, char **typep, struct berval *bvp )
{
char *value;
! int vlen, rc;
! if ( ldif_parse_line( typeval, typep, &value, &vlen ) != 0 ) {
return( LDAP_PARAM_ERROR );
}
rc = ldaptool_berval_from_ldif_value( value, vlen, bvp,
1 /* recognize file URLs */, 0 /* always try file */,
! 1 /* report errors */ );
return( ldaptool_fileurlerr2ldaperr( rc ));
}
--- 207,221 ----
typeval2berval( char *typeval, char **typep, struct berval *bvp )
{
char *value;
! int vlen, rc, fileURL;
! if ( ldif_parse_line( typeval, typep, &value, &vlen, &fileURL ) != 0 ) {
return( LDAP_PARAM_ERROR );
}
rc = ldaptool_berval_from_ldif_value( value, vlen, bvp,
1 /* recognize file URLs */, 0 /* always try file */,
! 1 /* report errors */, 0 );
return( ldaptool_fileurlerr2ldaperr( rc ));
}
Index: line64.c
===================================================================
RCS file: /m/src/mozilla/directory/c-sdk/ldap/libraries/libldif/line64.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 line64.c
*** line64.c 12 Mar 2002 18:01:31 -0000 1.1.1.1
--- line64.c 22 Jan 2008 22:08:10 -0000
***************
*** 86,97 ****
char *line,
char **type,
char **value,
! int *vlen
)
{
char *p, *s, *d;
int b64;
/* skip any leading space */
while ( ISBLANK( *line ) ) {
line++;
--- 86,100 ----
char *line,
char **type,
char **value,
! int *vlen,
! int *fileURL
)
{
char *p, *s, *d;
int b64;
+ *fileURL = 0;
+
/* skip any leading space */
while ( ISBLANK( *line ) ) {
line++;
***************
*** 126,131 ****
--- 129,140 ----
s++;
b64 = 1;
+ /* check for the file URL spec. Fix for 6653638 - MTR */
+ } else if( *s == '<' ){
+ s++;
+ *fileURL = 1;
+ b64 = 0;
+
/* single : - normally encoded value */
} else {
b64 = 0;
Index: ldif.h
===================================================================
RCS file: /m/src/mozilla/directory/c-sdk/ldap/include/ldif.h,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 ldif.h
*** ldif.h 12 Mar 2002 18:01:31 -0000 1.1.1.1
--- ldif.h 23 Jan 2008 20:42:07 -0000
***************
*** 68,74 ****
#define LDIF_OPT_VALUE_IS_URL 0x02UL
#define LDIF_OPT_MINIMAL_ENCODING 0x04UL
! int ldif_parse_line( char *line, char **type, char **value, int *vlen);
char * ldif_getline( char **next );
void ldif_put_type_and_value( char **out, char *t, char *val, int vlen );
void ldif_put_type_and_value_nowrap( char **out, char *t, char *val, int vlen
);
--- 68,74 ----
#define LDIF_OPT_VALUE_IS_URL 0x02UL
#define LDIF_OPT_MINIMAL_ENCODING 0x04UL
! int ldif_parse_line( char *line, char **type, char **value, int *vlen, int *fileURL);
char * ldif_getline( char **next );
void ldif_put_type_and_value( char **out, char *t, char *val, int vlen );
void ldif_put_type_and_value_nowrap( char **out, char *t, char *val, int vlen
);
Reporter | ||
Comment 3•17 years ago
|
||
I've revised my fix as it has been brought to my attention that the prototype change for ldif_parse_line() could cause issues.
This is a much simpler version of the fix:
Index: ldapmodify.c
===================================================================
RCS file: /m/src/mozilla/directory/c-sdk/ldap/clients/tools/ldapmodify.c,v
retrieving revision 1.1.1.1.2.3
diff -u -8 -p -r1.1.1.1.2.3 ldapmodify.c
--- ldapmodify.c 16 Aug 2004 14:18:39 -0000 1.1.1.1.2.3
+++ ldapmodify.c 24 Jan 2008 23:36:07 -0000
@@ -61,24 +61,25 @@ static int ldapmodify_quiet = 0;
/* bulk import */
#define BULKIMPORT_START_OID "2.16.840.1.113730.3.5.7"
#define BULKIMPORT_STOP_OID "2.16.840.1.113730.3.5.8"
static void options_callback( int option, char *optarg );
static int process_ldapmod_rec( char *rbuf );
static int process_ldif_rec( char *rbuf );
static void addmodifyop( LDAPMod ***pmodsp, int modop, char *attr,
- char *value, int vlen );
+ char *value, int vlen, int is_file_url );
static int domodify( char *dn, LDAPMod **pmods, int newentry );
static int dodelete( char *dn );
static int dorename( char *dn, char *newrdn, char *newparent,
int deleteoldrdn );
static void freepmods( LDAPMod **pmods );
static char *read_one_record( FILE *fp );
static char *strdup_and_trim( char *s );
+int is_starting_with_file_url(char *line):
static void
usage( void )
{
fprintf( stderr, "usage: %s [options]\n", ldaptool_progname );
fprintf( stderr, "options:\n" );
ldaptool_common_usage( 0 );
fprintf( stderr, " -c\t\tcontinuous mode (do not stop on errors)\n" );
@@ -293,30 +294,38 @@ options_callback( int option, char *opta
case 'q': /* quiet mode on add/modify operations */
ldapmodify_quiet = 1;
break;
default:
usage();
}
}
+int
+is_starting_with_file_url(char *line)
+{
+ while (*line && *line != ':' ) line++;
+
+ return ( strncmp(line,":<",2) == 0 );
+}
static int
process_ldif_rec( char *rbuf )
{
char *line, *dn, *type, *value, *newrdn, *newparent, *p;
char *ctrl_oid=NULL, *ctrl_value=NULL;
int ctrl_criticality=1;
LDAPControl *ldctrl;
int rc, linenum, vlen, modop, replicaport;
int expect_modop, expect_sep, expect_chgtype_or_control, expect_newrdn;
int expect_deleteoldrdn, expect_newparent, rename, moddn;
int deleteoldrdn, saw_replica, use_record, new_entry, delete_entry;
int got_all, got_value;
+ int is_file_url;
LDAPMod **pmods;
new_entry = newval;
rc = got_all = saw_replica = delete_entry = expect_modop = 0;
expect_deleteoldrdn = expect_newrdn = expect_newparent = expect_sep = 0;
expect_chgtype_or_control = linenum = got_value = rename = moddn = 0;
deleteoldrdn = 1;
@@ -329,22 +338,24 @@ process_ldif_rec( char *rbuf )
if ( expect_sep && strcasecmp( line, T_MODSEPSTR ) == 0 ) {
expect_sep = 0;
expect_modop = 1;
/*If we see a separator in the input stream,
but we didn't get a value from the last modify
then we have to fill pmods with an empty value*/
if (modop == LDAP_MOD_REPLACE && !got_value){
- addmodifyop( &pmods, modop, value, NULL, 0);
+ addmodifyop( &pmods, modop, value, NULL, 0, 0);
}
got_value = 0;
continue;
}
+
+ is_file_url = is_starting_with_file_url(line);
if ( ldif_parse_line( line, &type, &value, &vlen ) < 0 ) {
fprintf( stderr, "%s: invalid format (line %d of entry: %s)\n",
ldaptool_progname, linenum, dn == NULL ? "" : dn );
fprintf( stderr, "%s: line contents: (%s)\n",
ldaptool_progname, line );
rc = LDAP_PARAM_ERROR;
break;
@@ -480,17 +491,17 @@ evaluate_line:
if ( strcasecmp( type, T_MODOPADDSTR ) == 0 ) {
modop = LDAP_MOD_ADD;
continue;
} else if ( strcasecmp( type, T_MODOPREPLACESTR ) == 0 ) {
modop = LDAP_MOD_REPLACE;
continue;
} else if ( strcasecmp( type, T_MODOPDELETESTR ) == 0 ) {
modop = LDAP_MOD_DELETE;
- addmodifyop( &pmods, modop, value, NULL, 0 );
+ addmodifyop( &pmods, modop, value, NULL, 0, is_file_url );
continue;
} else { /*Bug 27479. Remove default add operation*/
fprintf(stderr, "%s: Invalid parameter \"%s\" specified for changetype modify (line %d
of entry %s)\n",
ldaptool_progname, type, linenum, dn);
rc = LDAP_PARAM_ERROR;
}
}
@@ -560,17 +571,17 @@ evaluate_line:
got_all = 1;
} else if ( got_all ) {
fprintf( stderr,
"%s: extra lines at end (line %d of entry %s)\n",
ldaptool_progname, linenum, dn );
rc = LDAP_PARAM_ERROR;
got_all = 1;
} else {
- addmodifyop( &pmods, modop, type, value, vlen );
+ addmodifyop( &pmods, modop, type, value, vlen, is_file_url );
/*There was a value to replace*/
got_value = 1;
}
}
if ( rc == 0 ) {
if ( delete_entry ) {
@@ -580,17 +591,17 @@ evaluate_line:
rename = 0;
} else {
/*Patch to fix Bug 22183
If pmods is null, then there is no
attribute to replace, so we alloc
an empty pmods*/
if (modop == LDAP_MOD_REPLACE && !got_value && expect_sep){
- addmodifyop( &pmods, modop, value, NULL, 0);
+ addmodifyop( &pmods, modop, value, NULL, 0, 0);
}/*End Patch*/
rc = domodify( dn, pmods, new_entry );
}
if ( rc == LDAP_SUCCESS ) {
rc = 0;
@@ -694,17 +705,17 @@ process_ldapmod_rec( char *rbuf )
default:
/*Bug 27479. Remove the add default*/
fprintf(stderr, "%s: Invalid parameter specified for changetype modify (line %
d of entry %s)\n",
ldaptool_progname, linenum, dn);
rc = LDAP_PARAM_ERROR;
}
addmodifyop( &pmods, modop, attr, value,
- ( value == NULL ) ? 0 : strlen( value ));
+ ( value == NULL ) ? 0 : strlen( value ), 0);
}
}
line = rbuf;
}
if ( rc == 0 ) {
if ( dn == NULL ) {
@@ -721,17 +732,17 @@ process_ldapmod_rec( char *rbuf )
free( dn );
}
return( rc );
}
static void
-addmodifyop( LDAPMod ***pmodsp, int modop, char *attr, char *value, int vlen )
+addmodifyop( LDAPMod ***pmodsp, int modop, char *attr, char *value, int vlen, int is_file_url )
{
LDAPMod **pmods;
int i, j, rc;
struct berval *bvp;
pmods = *pmodsp;
modop |= LDAP_MOD_BVALUES;
@@ -787,17 +798,17 @@ addmodifyop( LDAPMod ***pmodsp, int modo
pmods[ i ]->mod_bvalues[ j ] = bvp;
#ifdef notdef
if (ldaptool_verbose) {
printf("%s: value: %s vlen: %d\n", "ldapmodify", value, vlen);
}
#endif
rc = ldaptool_berval_from_ldif_value( value, vlen, bvp,
- ( ldif_version >= LDIF_VERSION_ONE ), valsfromfiles,
+ (( ldif_version >= LDIF_VERSION_ONE ) && is_file_url), valsfromfiles,
1 /* report errors */ );
if ( rc != LDAPTOOL_FILEURL_SUCCESS ) {
exit( ldaptool_fileurlerr2ldaperr( rc ));
}
}
}
Index: fileurl.h
===================================================================
RCS file: /m/src/mozilla/directory/c-sdk/ldap/clients/tools/fileurl.h,v
retrieving revision 1.1.1.1
diff -u -8 -p -r1.1.1.1 fileurl.h
--- fileurl.h 12 Mar 2002 18:01:31 -0000 1.1.1.1
+++ fileurl.h 24 Jan 2008 23:13:58 -0000
@@ -58,17 +58,17 @@ int ldaptool_path2fileurl( char *path, c
* If reporterrs is non-zero, specific error messages are printed to
* stderr.
*
* If successful, LDAPTOOL_FILEURL_SUCCESS is returned and bvp->bv_len
* and bvp->bv_val are set (the latter is set to malloc'd memory).
* Upon failure, a different LDAPTOOL_FILEURL_ error code is returned.
*/
int ldaptool_berval_from_ldif_value( const char *value, int vlen,
- struct berval *bvp, int recognize_url_syntax, int always_try_file,
+ struct berval *bvp, int is_file_url, int always_try_file,
int reporterrs );
/*
* Map an LDAPTOOL_FILEURL_ error code to an LDAP error code (crude).
*/
int ldaptool_fileurlerr2ldaperr( int lderr );
Index: fileurl.c
===================================================================
RCS file: /m/src/mozilla/directory/c-sdk/ldap/clients/tools/fileurl.c,v
retrieving revision 1.1.1.1.2.4
diff -u -8 -p -r1.1.1.1.2.4 fileurl.c
--- fileurl.c 28 May 2003 20:03:21 -0000 1.1.1.1.2.4
+++ fileurl.c 24 Jan 2008 23:30:37 -0000
@@ -60,16 +60,22 @@ static int berval_from_file( const char
*
*/
int
ldaptool_fileurl2path( const char *fileurl, char **localpathp )
{
const char *path;
char *pathcopy;
+ /*
+ * clean up the '<' and any white space from fileurl
+ */
+ if(*fileurl == '<') fileurl++;
+ while (*fileurl && *fileurl == ' ' ) fileurl++;
+
/*
* Make sure this is a file URL we can handle.
*/
if ( !str_starts_with( fileurl, "file:" )) {
return( LDAPTOOL_FILEURL_NOTAFILEURL );
}
path = fileurl + 5; /* skip past "file:" scheme prefix */
@@ -211,66 +217,52 @@ ldaptool_path2fileurl( char *path, char
* stderr.
*
* If successful, LDAPTOOL_FILEURL_SUCCESS is returned and bvp->bv_len
* and bvp->bv_val are set (the latter is set to malloc'd memory).
* Upon failure, a different LDAPTOOL_FILEURL_ error code is returned.
*/
int
ldaptool_berval_from_ldif_value( const char *value, int vlen,
- struct berval *bvp, int recognize_url_syntax, int always_try_file,
+ struct berval *bvp, int is_file_url, int always_try_file,
int reporterrs )
{
int rc = LDAPTOOL_FILEURL_SUCCESS; /* optimistic */
- const char *url = NULL;
struct stat fstats;
/* recognize "attr :< url" syntax if LDIF version is >= 1 */
#ifdef notdef
if ( ldaptool_verbose ) {
fprintf( stderr, "%s: ldaptool_berval_from_ldif_value: value: %s\n",
ldaptool_progname, value);
}
#endif
- if ( recognize_url_syntax && *value == '<' ) {
- for ( url = value + 1; isspace( *url ); ++url ) {
- ; /* NULL */
- }
-
- if (strlen(url) > 7 && strncasecmp(url, "file://", 7) != 0) {
- /*
- * We only support file:// URLs for now.
- */
- url = NULL;
- }
- }
-
- if ( NULL != url ) {
+ if ( is_file_url ) {
char *path;
- rc = ldaptool_fileurl2path( url, &path );
+ rc = ldaptool_fileurl2path( value, &path );
switch( rc ) {
case LDAPTOOL_FILEURL_NOTAFILEURL:
if ( reporterrs ) fprintf( stderr, "%s: unsupported URL \"%s\";"
- " use a file:// URL instead.\n", ldaptool_progname, url );
+ " use a file:// URL instead.\n", ldaptool_progname, value );
break;
case LDAPTOOL_FILEURL_MISSINGPATH:
if ( reporterrs ) fprintf( stderr,
"%s: unable to process URL \"%s\" --"
- " missing path.\n", ldaptool_progname, url );
+ " missing path.\n", ldaptool_progname, value );
break;
case LDAPTOOL_FILEURL_NONLOCAL:
if ( reporterrs ) fprintf( stderr,
"%s: unable to process URL \"%s\" -- only"
" local file:// URLs are supported.\n",
- ldaptool_progname, url );
+ ldaptool_progname, value );
break;
case LDAPTOOL_FILEURL_NOMEMORY:
if ( reporterrs ) perror( "ldaptool_fileurl2path" );
break;
case LDAPTOOL_FILEURL_SUCCESS:
if ( stat( path, &fstats ) != 0 ) {
@@ -284,17 +276,17 @@ ldaptool_berval_from_ldif_value( const c
rc = berval_from_file( path, bvp, reporterrs );
}
free( path );
break;
default:
if ( reporterrs ) fprintf( stderr,
"%s: unable to process URL \"%s\""
- " -- unknown error\n", ldaptool_progname, url );
+ " -- unknown error\n", ldaptool_progname, value );
}
} else if ( always_try_file && (stat( value, &fstats ) == 0) &&
!(fstats.st_mode & S_IFDIR)) { /* get value from file */
rc = berval_from_file( value, bvp, reporterrs );
} else {
bvp->bv_len = vlen;
if (( bvp->bv_val = (char *)malloc( vlen + 1 )) == NULL ) {
if ( reporterrs ) perror( "malloc" );
You need to log in
before you can comment on or make changes to this bug.
Description
•