summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralee <alee@c9f7a03b-bd48-0410-a16d-cbbf54688b0b>2009-06-12 19:51:16 +0000
committeralee <alee@c9f7a03b-bd48-0410-a16d-cbbf54688b0b>2009-06-12 19:51:16 +0000
commit84dc93a306bf65fe4fc1eaed1a8697dc21343592 (patch)
treedd4176098ec7776b4180dc6990b4c1fea8a6bab9
parent05103862d4b9d9e3d26cc3730d406ed8b870ca5a (diff)
Bugzilla Bug #489318 - TPS List Activites - does not list activities after 20 entries - fix pagination
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@586 c9f7a03b-bd48-0410-a16d-cbbf54688b0b
-rw-r--r--pki/base/tps/src/modules/tokendb/mod_tokendb.cpp93
-rw-r--r--pki/dogtag/tps/pki-tps.spec4
2 files changed, 58 insertions, 39 deletions
diff --git a/pki/base/tps/src/modules/tokendb/mod_tokendb.cpp b/pki/base/tps/src/modules/tokendb/mod_tokendb.cpp
index 387139081..b703f3c92 100644
--- a/pki/base/tps/src/modules/tokendb/mod_tokendb.cpp
+++ b/pki/base/tps/src/modules/tokendb/mod_tokendb.cpp
@@ -84,6 +84,7 @@ extern TOKENDB_PUBLIC char *nss_var_lookup( apr_pool_t *p, server_rec *s,
#define MAX_INJECTION_SIZE 5120
#define MAX_OVERLOAD 20
+#define LOW_INJECTION_SIZE 2048
#define SHORT_LEN 256
#define BASE64_HEADER "-----BEGIN CERTIFICATE-----\n"
@@ -2513,7 +2514,48 @@ void add_authorization_data(const char *userid, int is_admin, int is_operator, i
PL_strcat(injection, "var adminAuth = \"true\";\n");
}
}
-
+
+/**
+ * check_injection_size
+ * Used when the injection size can become large - as in the case where lists of tokens, certs or activities are being returned.
+ * If the free space in injection drops below a threshold, more space is allocated. Fails if injection exceeds a certain size.
+ * This should not happen because the number of entries to return per page is limited.
+ *
+ * returns 0 on success,1 on failure
+ */
+int check_injection_size(char **injection, int *psize, char *fixed_injection)
+{
+ char *new_ptr = NULL;
+ if (((*psize) - PL_strlen(*injection)) <= LOW_INJECTION_SIZE) {
+ if ((*psize) > MAX_OVERLOAD * MAX_INJECTION_SIZE) {
+ tokendbDebug("Error: Injection exceeds maximum size. Output will be truncated");
+ return 1;
+ }
+ if (*injection == fixed_injection) {
+ *injection = (char *) PR_Malloc(MAX_INJECTION_SIZE + (*psize));
+ if (*injection != NULL) {
+ PL_strcpy(*injection, fixed_injection);
+ (*psize) += MAX_INJECTION_SIZE;
+ } else {
+ tokendbDebug("Error: Unable to allocate memory for injection. Output will be truncated");
+ *injection = fixed_injection;
+ return 1;
+ }
+ } else {
+ new_ptr = (char *) PR_Realloc(*injection, (*psize) + MAX_INJECTION_SIZE);
+ if (new_ptr != NULL) {
+ //allocation successful
+ *injection = new_ptr;
+ (*psize) += MAX_INJECTION_SIZE;
+ } else {
+ tokendbDebug("Error: Failed to reallocate memory for injection. Output will be truncated");
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+
/**
* mod_tokendb_handler handles the protocol between the tokendb and the RA
@@ -2556,7 +2598,7 @@ mod_tokendb_handler( request_rec *rq )
char **vals = NULL;
int maxReturns;
int q;
- int i, n, len, maxEntries, nEntries, entryNum;
+ int i, n, len, nEntries, entryNum;
int status = LDAP_SUCCESS;
int size, tagOffset, statusNum;
char fixed_injection[MAX_INJECTION_SIZE];
@@ -3991,7 +4033,6 @@ mod_tokendb_handler( request_rec *rq )
do_free(complete_filter);
nEntries = get_number_of_entries( result );
entryNum = 0;
- maxEntries = 0;
size = 0;
PL_strcpy( injection, JS_START );
@@ -4123,6 +4164,7 @@ mod_tokendb_handler( request_rec *rq )
PL_strcat(injection, msg);
}
+ int injection_size = MAX_INJECTION_SIZE;
/* start_entry_val is used for pagination of entries on all other pages */
int start_entry_val;
int end_entry_val;
@@ -4137,6 +4179,11 @@ mod_tokendb_handler( request_rec *rq )
}
end_entry_val = start_entry_val + NUM_ENTRIES_PER_PAGE;
+ if( (maxReturns > 0) && (maxReturns < nEntries)) {
+ PR_snprintf(msg, 256, "var limited = %d ;\n", maxReturns);
+ PL_strcat( injection, msg);
+ }
+
for( e = get_first_entry( result );
( maxReturns > 0 ) && ( e != NULL );
e = get_next_entry( e ) ) {
@@ -4153,6 +4200,7 @@ mod_tokendb_handler( request_rec *rq )
// skip values not within the page range
if (entryNum == end_entry_val) {
PL_strcat( injection, "var has_more_entries = 1;\n");
+ break;
}
continue;
}
@@ -4215,30 +4263,12 @@ mod_tokendb_handler( request_rec *rq )
PL_strcat( injection, "results[item++] = o;\n" );
- len = PL_strlen( injection );
+ if (check_injection_size(&injection, &injection_size, fixed_injection) != 0) {
+ // failed to allocate more space to injection, truncating output
+ break;
+ }
if( first_pass == 1 && nEntries > 1 && sendPieces == 0 ) {
- if( ( nEntries * len ) > MAX_INJECTION_SIZE ) {
- size = nEntries;
- if( ( nEntries * len ) >
- ( MAX_OVERLOAD * MAX_INJECTION_SIZE ) ) {
- maxEntries = ( MAX_OVERLOAD * MAX_INJECTION_SIZE ) /
- len;
- size = maxEntries;
- }
-
- size *= len;
-
- injection = ( char* ) PR_Malloc( size );
-
- if( injection != NULL ) {
- PL_strcpy( injection, fixed_injection );
- } else {
- injection = fixed_injection;
- maxEntries = MAX_INJECTION_SIZE / len;
- size = MAX_INJECTION_SIZE;
- }
- }
first_pass=0;
PR_snprintf(msg, 256, "var start_entry_val = %d ; \nvar num_entries_per_page= %d ; \n",
@@ -4252,9 +4282,6 @@ mod_tokendb_handler( request_rec *rq )
injection[0] = '\0';
}
- if( maxEntries > 0 && entryNum >= maxEntries ) {
- break;
- }
}
if( result != NULL ) {
@@ -4262,16 +4289,6 @@ mod_tokendb_handler( request_rec *rq )
result = NULL;
}
- if( maxEntries > 0 && nEntries > 1 ) {
- PL_strcat( injection, "var limited = \"" );
-
- len = PL_strlen( injection );
-
- PR_snprintf( &injection[len], ( size-len ), "%d", entryNum );
-
- PL_strcat( injection, "\";\n" );
- }
-
/* populate the user roles */
if ((PL_strstr( query, "op=edit_user")) ||
(PL_strstr( query, "op=user_delete_confirm"))) {
diff --git a/pki/dogtag/tps/pki-tps.spec b/pki/dogtag/tps/pki-tps.spec
index 832cad45a..f1098f811 100644
--- a/pki/dogtag/tps/pki-tps.spec
+++ b/pki/dogtag/tps/pki-tps.spec
@@ -34,7 +34,7 @@
## Package Header Definitions
%define base_name %{base_prefix}-%{base_component}
%define base_version 1.1.0
-%define base_release 28
+%define base_release 29
%define base_group System Environment/Daemons
%define base_vendor Red Hat, Inc.
%define base_license LGPLv2 with exceptions
@@ -313,6 +313,8 @@ fi
###############################################################################
%changelog
+* Fri Jun 12 2009 Ade Lee <alee@redhat.com> 1.1.0-29
+- Bugzilla Bug #489318 - TPS List Activites - does not list activities after 20 entries - fix pagination
* Wed Jun 10 2009 Ade Lee <alee@redhat.com> 1.1.0-28
- Bugzilla Bug #504898 - RA: agent unable to revoke a cert
* Tue Jun 9 2009 Ade Lee <alee@redhat.com> 1.1.0-27