diff options
author | Endi Sukma Dewata <edewata@redhat.com> | 2012-03-24 02:27:47 -0500 |
---|---|---|
committer | Endi Sukma Dewata <edewata@redhat.com> | 2012-03-26 11:43:54 -0500 |
commit | 621d9e5c413e561293d7484b93882d985b3fe15f (patch) | |
tree | 638f3d75761c121d9a8fb50b52a12a6686c5ac5c /base/tps/tools/tus | |
parent | 40d3643b8d91886bf210aa27f711731c81a11e49 (diff) | |
download | pki-621d9e5c413e561293d7484b93882d985b3fe15f.tar.gz pki-621d9e5c413e561293d7484b93882d985b3fe15f.tar.xz pki-621d9e5c413e561293d7484b93882d985b3fe15f.zip |
Removed unnecessary pki folder.
Previously the source code was located inside a pki folder.
This folder was created during svn migration and is no longer
needed. This folder has now been removed and the contents have
been moved up one level.
Ticket #131
Diffstat (limited to 'base/tps/tools/tus')
-rw-r--r-- | base/tps/tools/tus/add.c | 117 | ||||
-rw-r--r-- | base/tps/tools/tus/test.c | 117 |
2 files changed, 234 insertions, 0 deletions
diff --git a/base/tps/tools/tus/add.c b/base/tps/tools/tus/add.c new file mode 100644 index 000000000..f88ae9753 --- /dev/null +++ b/base/tps/tools/tus/add.c @@ -0,0 +1,117 @@ +/* --- BEGIN COPYRIGHT BLOCK --- + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Copyright (C) 2007 Red Hat, Inc. + * All rights reserved. + * --- END COPYRIGHT BLOCK --- + */ + +#ifdef HAVE_CONFIG_H +#ifndef AUTOTOOLS_CONFIG_H +#define AUTOTOOLS_CONFIG_H + +/* Eliminate warnings when using Autotools */ +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_VERSION + +#include <config.h> +#endif /* AUTOTOOLS_CONFIG_H */ +#endif /* HAVE_CONFIG_H */ + +#include "nsapi.h" + +#include <time.h> +#include <stdlib.h> +#include <stdio.h> +#include "ldap.h" + +#include "tus/tus_db.h" + +/* Specify the search criteria here. */ +static char *host = "localhost"; +static int port = 389; +static char *baseDN = "ou=Tokens,dc=mcom,dc=com"; +static char *prefix = "0000"; +static char *suffix = "0000"; +static int start = 1; +static int len = 0; +static char *who = NULL; +static char *password = NULL; +static char *token_type = NULL; + + +#define SCOPE LDAP_SCOPE_SUBTREE +#define FILTER "(cn=*)" + +int main (int argc, char **argv) +{ + int i, h, rc; + char cn[256]; + char *errorMsg = NULL; + + if (argc < 9 || argc > 11) { + printf ("Usage:\n %s baseDN prefix suffix start len who password token_type host port", argv[0]); + return 1; + } + + baseDN = argv[1]; + prefix = argv[2]; + suffix = argv[3]; + start = atoi(argv[4]); + len = atoi(argv[5]); + who = argv[6]; + password = argv[7]; + token_type = argv[8]; + + if (argc > 9) { + host = argv[9]; + } + + if (argc > 10) { + port = atoi(argv[10]); + } + + set_tus_db_baseDN(baseDN); + set_tus_db_port(port); + set_tus_db_host(host); + set_tus_db_bindDN(who); + set_tus_db_bindPass(password); + rc = tus_db_init(errorMsg); + if (rc != LDAP_SUCCESS) { + fprintf(stderr, "tus_db_init: (%d) %s\n", rc, errorMsg); + return 1; + } + + for (i = 0; i < len; i++) { + h = start + i; + sprintf(cn, "%s%08X%s", prefix, h, suffix); + printf ("Adding %s\n", cn); + + rc = add_default_tus_db_entry (NULL, "", cn, "active", "", "", token_type); + if (rc != LDAP_SUCCESS) { + fprintf( stderr, "ldap_add_ext_s: %s\n", ldap_err2string( rc ) ); + return 1; + } + } + + /* STEP 4: Disconnect from the server. */ + tus_db_end(); + + return( 0 ); +} diff --git a/base/tps/tools/tus/test.c b/base/tps/tools/tus/test.c new file mode 100644 index 000000000..a307d1ccc --- /dev/null +++ b/base/tps/tools/tus/test.c @@ -0,0 +1,117 @@ +/* --- BEGIN COPYRIGHT BLOCK --- + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Copyright (C) 2007 Red Hat, Inc. + * All rights reserved. + * --- END COPYRIGHT BLOCK --- + */ + +#ifdef HAVE_CONFIG_H +#ifndef AUTOTOOLS_CONFIG_H +#define AUTOTOOLS_CONFIG_H + +/* Eliminate warnings when using Autotools */ +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_VERSION + +#include <config.h> +#endif /* AUTOTOOLS_CONFIG_H */ +#endif /* HAVE_CONFIG_H */ + +#include <stdio.h> +#include "ldap.h" +#include "ldappr.h" + +/* Specify the search criteria here. */ +#define HOSTNAME "localhost" +#define PORTNUMBER 389 +#define BASEDN "ou=Tokens,dc=mcom,dc=com" +#define SCOPE LDAP_SCOPE_SUBTREE +#define FILTER "(cn=*)" + +int +main( int argc, char **argv ) +{ + char ldapuri[1024]; + LDAP *ld; + LDAPMessage *result = NULL, *e; + char *dn = NULL; + int version, rc; + /* Print out an informational message. */ + printf( "Connecting to host %s at port %d...\n\n", HOSTNAME, + PORTNUMBER ); + + /* STEP 1: Get a handle to an LDAP connection and + set any session preferences. */ + snprintf(ldapuri, 1024, "ldap://%s:%i", HOSTNAME, PORTNUMBER); + rc = ldap_initialize(&ld, ldapuri); + + if ( ld == NULL ) { + perror( "ldap_initialize" ); + return( 1 ); + } + + /* Use the LDAP_OPT_PROTOCOL_VERSION session preference to specify + that the client is an LDAPv3 client. */ + version = LDAP_VERSION3; + ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version ); + + /* STEP 2: Bind to the server. + In this example, the client binds anonymously to the server + (no DN or credentials are specified). */ + rc = ldap_sasl_bind_s(ld, NULL, LDAP_SASL_SIMPLE, NULL, NULL, NULL, NULL); + if ( rc != LDAP_SUCCESS ) { + fprintf(stderr, "ldap_simple_bind_s: %s\n", ldap_err2string(rc)); + return( 1 ); + } + + /* Print out an informational message. */ + printf( "Searching the directory for entries\n" + " starting from the base DN %s\n" + " within the scope %d\n" + " matching the search filter %s...\n\n", + BASEDN, SCOPE, FILTER ); + + /* STEP 3: Perform the LDAP operations. + In this example, a simple search operation is performed. + The client iterates through each of the entries returned and + prints out the DN of each entry. */ + rc = ldap_search_ext_s( ld, BASEDN, SCOPE, FILTER, NULL, 0, + NULL, NULL, NULL, 0, &result ); + if ( rc != LDAP_SUCCESS ) { + fprintf(stderr, "ldap_search_ext_s: %s\n", ldap_err2string(rc)); + return( 1 ); + } + for ( e = ldap_first_entry( ld, result ); e != NULL; + e = ldap_next_entry( ld, e ) ) { + if ( (dn = ldap_get_dn( ld, e )) != NULL ) { + printf( "dn: %s\n", dn ); + ldap_memfree( dn ); + dn = NULL; + } + } + if( result != NULL ) { + ldap_msgfree( result ); + result = NULL; + } + + /* STEP 4: Disconnect from the server. */ + ldap_unbind_ext_s( ld, NULL, NULL ); + return( 0 ); +} |