From dfae5e3a46061f6bdf28db3dd0c22b08f8af5f70 Mon Sep 17 00:00:00 2001 From: cvs2svn Date: Thu, 14 Oct 2004 01:27:00 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create tag 'ext_bones_merge_dest'. Sprout from exp_bones 2004-09-14 02:15:45 UTC cvs2svn 'This commit was manufactured by cvs2svn to create branch 'exp_bones'.' Cherrypick from master 2004-10-14 01:26:59 UTC Master Builder 'Incremented build number [GLBUILDER]': org.glite.lb.server/Makefile org.glite.lb.server/config/startup org.glite.lb.server/project/configure.properties.xml org.glite.lb.server/project/version.properties org.glite.lb.server/src/bkserverd.c org.glite.lb.server/src/il_notification.c org.glite.lb.server/src/il_notification.h org.glite.lb.server/src/lb_authz.c org.glite.lb.server/src/lb_authz.h org.glite.lb.server/src/lb_proto.c org.glite.lb.server/src/lbs_db.c org.glite.lb.server/src/notification.c org.glite.lb.server/test/oneJob.qry org.glite.lb.server/test/test_query_events.cpp --- org.glite.lb.server/Makefile | 21 +- org.glite.lb.server/config/startup | 16 +- .../project/configure.properties.xml | 4 + org.glite.lb.server/project/version.properties | 6 +- org.glite.lb.server/src/bkserverd.c | 12 +- org.glite.lb.server/src/il_notification.c | 3 +- org.glite.lb.server/src/il_notification.h | 1 + org.glite.lb.server/src/lb_authz.c | 127 +++---- org.glite.lb.server/src/lb_authz.h | 8 +- org.glite.lb.server/src/lb_proto.c | 6 + org.glite.lb.server/src/lbs_db.c | 5 +- org.glite.lb.server/src/notification.c | 376 ++++++++++++++++----- org.glite.lb.server/test/oneJob.qry | 24 ++ org.glite.lb.server/test/test_query_events.cpp | 152 +++++++++ 14 files changed, 584 insertions(+), 177 deletions(-) create mode 100644 org.glite.lb.server/test/oneJob.qry create mode 100644 org.glite.lb.server/test/test_query_events.cpp diff --git a/org.glite.lb.server/Makefile b/org.glite.lb.server/Makefile index bf01a86..5b168c2 100644 --- a/org.glite.lb.server/Makefile +++ b/org.glite.lb.server/Makefile @@ -20,6 +20,7 @@ ares_prefix=/opt/ares -include Makefile.inc YACC=bison -y +CC=gcc VPATH=${top_srcdir}/src:${top_srcdir}/test AT3=perl -I${top_srcdir}/project ${top_srcdir}/project/at3 @@ -42,7 +43,8 @@ CFLAGS:= -DNO_VOMS -DNO_GACL \ -I${ares_prefix}/include \ ${COVERAGE_FLAGS} \ -I${mysql_prefix}/include \ - -I${globus_prefix}/include/${nothrflavour} + -I${globus_prefix}/include/${nothrflavour} \ + -I${gridsite_prefix}/include -I${globus_prefix}/include/${nothrflavour}/openssl TEST_LIBS:=-L${cppunit}/lib -lcppunit @@ -59,7 +61,7 @@ LINKXX:=libtool --mode=link ${CXX} -rpath ${stagedir}/lib ${LDFLAGS} GLOBUS_LIBS:= -L${globus_prefix}/lib \ -lglobus_common_${nothrflavour} \ - -lglobus_gssapi_gsi_${nothrflavour} + -lglobus_gssapi_gsi_${nothrflavour} \ # XXX: our vomsc.la depends on badly installed expat @@ -73,8 +75,12 @@ EXT_LIBS:= -L${ares_prefix}/lib -lares \ -L${expat_prefix}/lib -lexpat \ ${GLOBUS_LIBS} +# -L${gridsite_prefix}/lib -lgridsite -lxml2 + COMMON_LIB:= -L${stagedir}/lib -lglite_lb_common_${nothrflavour} +# -lvomsc + SERVER_OBJS:= bkserverd.o get_events.o index.o jobstat.o jobstat_supp.o \ write2rgma.o lbs_db.o lb_html.o lb_http.o lb_proto.o lb_xml_parse.o \ lb_xml_parse_V21.o \ @@ -96,12 +102,17 @@ default all: compile compile: glite_lb_bkserverd glite_lb_bkindex -check: test_xml +check: compile test.xml test.query -echo check.query not complete yet test_xml: test_xml.cpp ${CXX} -c ${CFLAGS} ${TEST_INC} $< - ${LINKXX} -o $@ test_xml.o lb_xml_parse.o ${COMMON_LIB} ${TEST_LIBS} + ${LINKXX} -o $@ test_xml.o lb_xml_parse.o ${COMMON_LIB} ${TEST_LIBS} ${EXT_LIBS} + +test.query: test_query_events + ./test_query_events ${top_srcdir}/test + +test.xml: test_xml ./test_xml lb_xml_parse.c: lb_xml_parse.c.T @@ -142,6 +153,8 @@ distbin: install: -mkdir -p ${PREFIX}/bin ${PREFIX}/etc ${PREFIX}/etc/init.d + -mkdir -p ${PREFIX}/share/doc/${package}-${version} + ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version} for p in bkserverd bkindex; do \ ${INSTALL} -m 755 "glite_lb_$$p" "${PREFIX}/bin/glite-lb-$$p"; \ done diff --git a/org.glite.lb.server/config/startup b/org.glite.lb.server/config/startup index 8e26908..3acda57 100755 --- a/org.glite.lb.server/config/startup +++ b/org.glite.lb.server/config/startup @@ -11,7 +11,7 @@ GLITE_LOCATION_VAR=/opt/glite/var [ -f $GLITE_LOCATION_VAR/etc/lb.conf ] && . $GLITE_LOCATION_VAR/etc/lb.conf [ -n "$GLITE_LB_SERVER_PIDFILE" ] && pidfile=$GLITE_LB_SERVER_PIDFILE || - pidfile=$GLITE_LOCATION_VAR/glite_lb_bkserverd.pid + pidfile=$GLITE_LOCATION_VAR/glite-lb-bkserverd.pid start() { @@ -22,9 +22,9 @@ start() [ -n "$GLITE_LB_SERVER_PORT" ] && port="-p $GLITE_LB_SERVER_PORT" - echo -n Starting glite_lb_bkserver ... - su $GLITE_USER -c "$GLITE_LOCATION/bin/glite_lb_bkserverd \ - $creds -i $pidfile" && echo " done" + echo -n Starting glite-lb-bkserver ... + su $GLITE_USER -c "$GLITE_LOCATION/bin/glite-lb-bkserverd \ + $creds -i $pidfile $port" && echo " done" } stop() @@ -32,7 +32,7 @@ stop() if [ -f $pidfile ]; then pid=`cat $pidfile` kill $pid - echo -n Stopping glite_lb_bkserverd \($pid\) ... + echo -n Stopping glite-lb-bkserverd \($pid\) ... try=0 while ps p $pid >/dev/null 2>&1; do sleep 1; @@ -45,7 +45,7 @@ stop() echo " done" rm -f $pidfile else - echo $pidfile does not exist - glite_lb_bkserverd not running? >&2 + echo $pidfile does not exist - glite-lb-bkserverd not running? >&2 return 1 fi } @@ -55,12 +55,12 @@ status() if [ -f $pidfile ]; then pid=`cat $pidfile` if ps p $pid >/dev/null 2>&1; then - echo glite_lb_bkserverd running as $pid + echo glite-lb-bkserverd running as $pid return 0 fi fi - echo glite_lb_bkserverd not running + echo glite-lb-bkserverd not running return 1 } diff --git a/org.glite.lb.server/project/configure.properties.xml b/org.glite.lb.server/project/configure.properties.xml index 66ea055..f01fbda 100644 --- a/org.glite.lb.server/project/configure.properties.xml +++ b/org.glite.lb.server/project/configure.properties.xml @@ -20,6 +20,9 @@ Revision history: $Log$ + Revision 1.2 2004/09/08 13:38:03 akrenek + query event unit test (not complete yet) + Revision 1.1 2004/07/07 12:08:09 akrenek *** empty log message *** @@ -56,6 +59,7 @@ expat_prefix=${with.expat.prefix} ares_prefix=${with.ares.prefix} mysql_prefix=${with.mysql.prefix} cppunit=${with.cppunit.prefix} +gridsite_prefix=${with.gridsite.prefix} diff --git a/org.glite.lb.server/project/version.properties b/org.glite.lb.server/project/version.properties index 096ec36..8566fde 100644 --- a/org.glite.lb.server/project/version.properties +++ b/org.glite.lb.server/project/version.properties @@ -1,4 +1,4 @@ -#Tue Sep 14 04:13:15 CEST 2004 -module.version=0.0.0 -module.build=7 +#Thu Oct 14 03:24:40 CEST 2004 +module.version=0.1.0 +module.build=41 module.age=0 diff --git a/org.glite.lb.server/src/bkserverd.c b/org.glite.lb.server/src/bkserverd.c index 4d8f10b..811935a 100644 --- a/org.glite.lb.server/src/bkserverd.c +++ b/org.glite.lb.server/src/bkserverd.c @@ -30,7 +30,6 @@ #include -#include "glite/wmsutils/tls/ssl_helpers/ssl_inits.h" #include "glite/lb/consumer.h" #include "glite/lb/purge.h" #include "glite/lb/context.h" @@ -149,6 +148,7 @@ static struct option opts[] = { {"limits", 1, NULL, 'L'}, {"notif-dur", 1, NULL, 'N'}, {"notif-il-sock", 1, NULL, 'X'}, + {"notif-il-fprefix", 1, NULL, 'Y'}, {NULL,0,NULL,0} }; @@ -178,6 +178,7 @@ static void usage(char *me) "\t =2\t don't enforce indices at all\n" "\t--strict-locking=1\t lock jobs also on storing events (may be slow)\n" "\t--notif-il-sock\t socket to send notifications\n" + "\t--notif-il-fprefix\t file prefix for notifications\n" ,me); } @@ -505,7 +506,7 @@ int main(int argc,char *argv[]) if (geteuid()) snprintf(pidfile,sizeof pidfile,"%s/edg-bkserverd.pid", getenv("HOME")); - while ((opt = getopt_long(argc,argv,"a:c:k:C:V:p:drm:ns:l:L:N:i:S:D:X:",opts,NULL)) != EOF) switch (opt) { + while ((opt = getopt_long(argc,argv,"a:c:k:C:V:p:drm:ns:l:L:N:i:S:D:X:Y:",opts,NULL)) != EOF) switch (opt) { case 'a': fake_host = strdup(optarg); break; case 'c': cert = optarg; break; case 'k': key = optarg; break; @@ -529,6 +530,7 @@ int main(int argc,char *argv[]) break; case 'N': notif_duration = atoi(optarg) * (60*60); break; case 'X': notif_ilog_socket_path = strdup(optarg); break; + case 'Y': notif_ilog_file_prefix = strdup(optarg); break; case 'i': strcpy(pidfile,optarg); break; case 'R': if (super_users) { fprintf(stderr,"%s: super-users already defined, second occurence ignored\n", @@ -663,7 +665,8 @@ int main(int argc,char *argv[]) if (!cert || !key) fprintf(stderr,"%s: key or certificate file not specified - unable to watch them for changes!\n",argv[0]); if (cadir) setenv("X509_CERT_DIR",cadir,1); - if (edg_wll_gss_acquire_cred_gsi(cert, &mycred, &mysubj, &gss_code)) { + edg_wll_gss_watch_creds(cert,&cert_mtime); + if (edg_wll_gss_acquire_cred_gsi(cert, key, &mycred, &mysubj, &gss_code)) { dprintf(("Running unauthenticated\n")); } else { int i; @@ -745,7 +748,7 @@ int main(int argc,char *argv[]) switch (edg_wll_gss_watch_creds(cert,&cert_mtime)) { case 0: break; case 1: - ret = edg_wll_gss_acquire_cred_gsi(cert, &newcred, NULL, &gss_code); + ret = edg_wll_gss_acquire_cred_gsi(cert, key, &newcred, NULL, &gss_code); if (ret == 0) { dprintf(("reloading credentials")); gss_release_cred(&min_stat, &mycred); @@ -1126,6 +1129,7 @@ static int slave(void *mycred,int sock) ctx->p_tmp_timeout.tv_sec = SLAVE_TIMEOUT; ctx->poolSize = 1; + free(ctx->connPool); ctx->connPool = calloc(1,sizeof(edg_wll_ConnPool)); ctx->connToUse = 0; diff --git a/org.glite.lb.server/src/il_notification.c b/org.glite.lb.server/src/il_notification.c index 5ac8c53..0744d13 100644 --- a/org.glite.lb.server/src/il_notification.c +++ b/org.glite.lb.server/src/il_notification.c @@ -31,6 +31,7 @@ #define DEFAULT_SOCKET "/tmp/notif_interlogger.sock" char *notif_ilog_socket_path = DEFAULT_SOCKET; +char *notif_ilog_file_prefix = FILE_PREFIX; #define tv_sub(a,b) {\ (a).tv_usec -= (b).tv_usec;\ @@ -312,7 +313,7 @@ edg_wll_NotifSend(edg_wll_Context context, goto out; } - asprintf(&event_file, "%s.%s", FILE_PREFIX, reg_id_s); + asprintf(&event_file, "%s.%s", notif_ilog_file_prefix, reg_id_s); if(event_file == NULL) { edg_wll_SetError(context, ret=ENOMEM, "asprintf()"); goto out; diff --git a/org.glite.lb.server/src/il_notification.h b/org.glite.lb.server/src/il_notification.h index 3c842c9..f76a829 100644 --- a/org.glite.lb.server/src/il_notification.h +++ b/org.glite.lb.server/src/il_notification.h @@ -13,6 +13,7 @@ #endif extern char *notif_ilog_socket_path; +extern char *notif_ilog_file_prefix; /** Send ULM notification string to interlogger. * Stores notification to file according to registration id and send it diff --git a/org.glite.lb.server/src/lb_authz.c b/org.glite.lb.server/src/lb_authz.c index 9eb17e2..3ade941 100644 --- a/org.glite.lb.server/src/lb_authz.c +++ b/org.glite.lb.server/src/lb_authz.c @@ -7,11 +7,11 @@ #ifndef NO_VOMS -#include #include #include #undef WITHOUT_TRIO +#include "glite/security/voms/voms_apic.h" #include "glite/wmsutils/jobid/strmd5.h" #include "glite/wmsutils/jobid/cjobid.h" #include "glite/lb/producer.h" @@ -19,7 +19,8 @@ #include "lb_authz.h" #include "lbs_db.h" -GACLentry *GACLparseEntry(xmlNodePtr cur); +/* XXX should be defined in gridsite-gacl.h */ +GRSTgaclEntry *GACLparseEntry(xmlNodePtr cur); static int add_groups(edg_wll_Context ctx, struct voms *voms_cert, char *vo_name, @@ -86,10 +87,16 @@ get_peer_cred(edg_wll_GssConnection *gss, STACK_OF(X509) **chain, X509 **cert) X509 *peer_cert = NULL; X509 *p_cert; - maj_stat = gss_export_sec_context(&min_stat, gss->context, &buffer); + maj_stat = gss_export_sec_context(&min_stat, &gss->context, &buffer); if (GSS_ERROR(maj_stat)) return -1; /* XXX */ + /* The GSSAPI specs requires gss_export_sec_context() to destroy the context + * after exporting. So we have to resurrect the context here by importing + * from just generated buffer. I'm eagerly waiting for adaptations in the + * VOMS API to avoid these hacks */ + maj_stat = gss_import_sec_context(&min_stat, &buffer, &gss->context); + bio = BIO_new(BIO_s_mem()); if (bio == NULL) { ret = -1; @@ -233,25 +240,25 @@ void edg_wll_FreeVomsGroups() {} #if !defined(NO_VOMS) && !defined(NO_GACL) static int -parse_creds(edg_wll_VomsGroups *groups, char *subject, GACLuser **gacl_user) +parse_creds(edg_wll_VomsGroups *groups, char *subject, GRSTgaclUser **gacl_user) { - GACLcred *cred = NULL; - GACLuser *user = NULL; + GRSTgaclCred *cred = NULL; + GRSTgaclUser *user = NULL; int ret; int i; - GACLinit(); + GRSTgaclInit(); - cred = GACLnewCred("person"); + cred = GRSTgaclCredNew("person"); if (cred == NULL) return ENOMEM; - if (!GACLaddToCred(cred, "dn", subject)) { + if (!GRSTgaclCredAddValue(cred, "dn", subject)) { ret = EINVAL; /* GACL_ERR */ goto fail; } - user = GACLnewUser(cred); + user = GRSTgaclUserNew(cred); if (user == NULL) { ret = ENOMEM; goto fail; @@ -259,17 +266,17 @@ parse_creds(edg_wll_VomsGroups *groups, char *subject, GACLuser **gacl_user) cred = NULL; /* GACLnewUser() doesn't copy content, just store the pointer */ for (i = 0; i < groups->len; i++) { - cred = GACLnewCred("voms-cred"); + cred = GRSTgaclCredNew("voms-cred"); if (cred == NULL) { ret = ENOMEM; goto fail; } - if (!GACLaddToCred(cred, "vo", groups->val[i].vo) || - !GACLaddToCred(cred, "group", groups->val[i].name)) { + if (!GRSTgaclCredAddValue(cred, "vo", groups->val[i].vo) || + !GRSTgaclCredAddValue(cred, "group", groups->val[i].name)) { ret = EINVAL; /* GACL_ERR */ goto fail; } - if (!GACLuserAddCred(user, cred)) { + if (!GRSTgaclUserAddCred(user, cred)) { ret = EINVAL; /* GACL_ERR */ goto fail; } @@ -284,20 +291,20 @@ parse_creds(edg_wll_VomsGroups *groups, char *subject, GACLuser **gacl_user) fail: if (cred) - GACLfreeCred(cred); + GRSTgaclCredFree(cred); if (user) - GACLfreeUser(user); + GRSTgaclUserFree(user); return ret; } static int -cmp_gacl_names(struct _GACLnamevalue *n1, struct _GACLnamevalue *n2) +cmp_gacl_names(GRSTgaclNamevalue *n1, GRSTgaclNamevalue *n2) { if (n1 == NULL && n2 == NULL) return 1; - for ( ; n1; n1 = n1->next, n2 = n2->next) { + for ( ; n1; n1 = (GRSTgaclNamevalue *)n1->next, n2 = (GRSTgaclNamevalue *) n2->next) { if (n2 == NULL) return 0; if (strcmp(n1->name, n2->name) != 0 || @@ -309,7 +316,7 @@ cmp_gacl_names(struct _GACLnamevalue *n1, struct _GACLnamevalue *n2) } static int -cmp_gacl_creds(GACLcred *c1, GACLcred *c2) +cmp_gacl_creds(GRSTgaclCred *c1, GRSTgaclCred *c2) { if (strcmp(c1->type, c2->type) != 0) return 0; @@ -320,16 +327,16 @@ cmp_gacl_creds(GACLcred *c1, GACLcred *c2) } static int -addEntry(GACLacl *acl, GACLentry *entry) +addEntry(GRSTgaclAcl *acl, GRSTgaclEntry *entry) { - GACLentry *cur = NULL; + GRSTgaclEntry *cur = NULL; if ( acl == NULL ) return EINVAL; if ( acl->firstentry == NULL ) - return (GACLaddEntry(acl, entry) == 0) ? -1 /* GACL_ERR */ : 0; + return (GRSTgaclAclAddEntry(acl, entry) == 0) ? -1 /* GACL_ERR */ : 0; for ( cur = acl->firstentry; cur; cur = cur->next ) if ( cmp_gacl_creds(cur->firstcred, entry->firstcred) @@ -337,13 +344,13 @@ addEntry(GACLacl *acl, GACLentry *entry) && cur->denied == entry->denied ) return EEXIST; - return (GACLaddEntry(acl, entry) == 0) ? -1 /* GACL_ERR */ : 0; + return (GRSTgaclAclAddEntry(acl, entry) == 0) ? -1 /* GACL_ERR */ : 0; } static int -delEntry(GACLacl *acl, GACLentry *entry) +delEntry(GRSTgaclAcl *acl, GRSTgaclEntry *entry) { - GACLentry *cur = NULL, *prev = NULL; + GRSTgaclEntry *cur = NULL, *prev = NULL; int found = 0; if (acl == NULL || acl->firstentry == NULL) @@ -358,7 +365,7 @@ delEntry(GACLacl *acl, GACLentry *entry) prev->next = cur->next; else acl->firstentry = cur->next; - GACLfreeEntry(cur); + GRSTgaclEntryFree(cur); found = 1; break; } @@ -370,30 +377,30 @@ delEntry(GACLacl *acl, GACLentry *entry) } static int -create_cred(char *userid, int user_type, GACLcred **cred) +create_cred(char *userid, int user_type, GRSTgaclCred **cred) { - GACLcred *c = NULL; + GRSTgaclCred *c = NULL; char *group = NULL; if (user_type == EDG_WLL_USER_SUBJECT) { - c = GACLnewCred("person"); + c = GRSTgaclCredNew("person"); if (c == NULL) return ENOMEM; - if (!GACLaddToCred(c, "dn", userid)) { - GACLfreeCred(c); + if (!GRSTgaclCredAddValue(c, "dn", userid)) { + GRSTgaclCredFree(c); return -1; /* GACL_ERR */ } } else if(user_type == EDG_WLL_USER_VOMS_GROUP) { - c = GACLnewCred("voms-cred"); + c = GRSTgaclCredNew("voms-cred"); if (c == NULL) return ENOMEM; group = strchr(userid, ':'); if ( !group ) return EINVAL; *group++ = '\0'; - if (!GACLaddToCred(c, "vo", userid) || - !GACLaddToCred(c, "group", group)) { - GACLfreeCred(c); + if (!GRSTgaclCredAddValue(c, "vo", userid) || + !GRSTgaclCredAddValue(c, "group", group)) { + GRSTgaclCredFree(c); return -1; /* GACL_ERR */ } } else @@ -405,7 +412,7 @@ create_cred(char *userid, int user_type, GACLcred **cred) } static int -change_acl(GACLacl *acl, GACLentry *entry, int operation) +change_acl(GRSTgaclAcl *acl, GRSTgaclEntry *entry, int operation) /* creds, permission, permission_type */ { if (operation == EDG_WLL_ACL_ADD) @@ -421,11 +428,11 @@ static int edg_wll_change_acl(edg_wll_Acl acl, char *user_id, int user_id_type, int permission, int perm_type, int operation) { - GACLcred *cred = NULL; - GACLentry *entry = NULL; + GRSTgaclCred *cred = NULL; + GRSTgaclEntry *entry = NULL; int ret; - GACLinit(); + GRSTgaclInit(); if (acl == NULL || acl->value == NULL) return EINVAL; @@ -434,21 +441,21 @@ edg_wll_change_acl(edg_wll_Acl acl, char *user_id, int user_id_type, if (ret) return ret; - entry = GACLnewEntry(); + entry = GRSTgaclEntryNew(); if (entry == NULL) { ret = ENOMEM; goto end; } - if (!GACLaddCred(entry, cred)) { + if (!GRSTgaclEntryAddCred(entry, cred)) { ret = -1; /* GACLErr */ goto end; } if (perm_type == EDG_WLL_PERM_ALLOW) - GACLallowPerm(entry, permission); + GRSTgaclEntryAllowPerm(entry, permission); else if (perm_type == EDG_WLL_PERM_DENY) - GACLdenyPerm(entry, permission); + GRSTgaclEntryDenyPerm(entry, permission); else { ret = EINVAL; goto end; @@ -458,7 +465,7 @@ edg_wll_change_acl(edg_wll_Acl acl, char *user_id, int user_id_type, if (ret) { /* XXX: mem leak? - GACLfreeEntry(entry); + GRSTgaclEntryFree(entry); */ goto end; } @@ -475,8 +482,8 @@ int edg_wll_CheckACL(edg_wll_Context ctx, edg_wll_Acl acl, int requested_perm) { int ret; - GACLuser *user = NULL; - GACLperm perm; + GRSTgaclUser *user = NULL; + unsigned int perm; if (acl == NULL || acl->value == NULL) return edg_wll_SetError(ctx,EINVAL,"CheckACL"); @@ -488,16 +495,16 @@ edg_wll_CheckACL(edg_wll_Context ctx, edg_wll_Acl acl, int requested_perm) return edg_wll_SetError(ctx,ret,"parse_creds()"); } - perm = GACLtestUserAcl(acl->value, user); + perm = GRSTgaclAclTestUser(acl->value, user); - GACLfreeUser(user); + /* XXX GRSTgaclUserFree(user); */ if (perm & requested_perm) return edg_wll_ResetError(ctx); else return edg_wll_SetError(ctx,EPERM,"CheckACL"); } int -edg_wll_EncodeACL(GACLacl *acl, char **str) +edg_wll_EncodeACL(GRSTgaclAcl *acl, char **str) { int tmp_fd, ret; FILE *fd = NULL; @@ -514,7 +521,7 @@ edg_wll_EncodeACL(GACLacl *acl, char **str) fd = fdopen(tmp_fd, "r"); - ret = GACLsaveAcl(filename, acl); + ret = GRSTgaclAclSave(acl, filename); unlink(filename); if (ret == 0) { ret = -1; /* GACL_ERR */ @@ -557,13 +564,13 @@ end: } int -edg_wll_DecodeACL(char *buf, GACLacl **result_acl) +edg_wll_DecodeACL(char *buf, GRSTgaclAcl **result_acl) { /* Got from GACLloadAcl() available from GACL API */ xmlDocPtr doc; xmlNodePtr cur; - GACLacl *acl; - GACLentry *entry; + GRSTgaclAcl *acl; + GRSTgaclEntry *entry; doc = xmlParseMemory(buf, strlen(buf)); if (doc == NULL) return EINVAL; @@ -579,7 +586,7 @@ edg_wll_DecodeACL(char *buf, GACLacl **result_acl) cur = cur->xmlChildrenNode; - acl = GACLnewAcl(); + acl = GRSTgaclAclNew(); while (cur != NULL) { @@ -592,12 +599,12 @@ edg_wll_DecodeACL(char *buf, GACLacl **result_acl) entry = GACLparseEntry(cur); if (entry == NULL) { - GACLfreeAcl(acl); + GRSTgaclAclFree(acl); xmlFreeDoc(doc); return EINVAL; } - GACLaddEntry(acl, entry); + GRSTgaclAclAddEntry(acl, entry); cur=cur->next; } @@ -616,7 +623,7 @@ edg_wll_InitAcl(edg_wll_Acl *acl) if ( !tmp ) return ENOMEM; - tmp->value = GACLnewAcl(); + tmp->value = GRSTgaclAclNew(); tmp->string = NULL; *acl = tmp; return 0; @@ -625,7 +632,7 @@ edg_wll_InitAcl(edg_wll_Acl *acl) void edg_wll_FreeAcl(edg_wll_Acl acl) { - if ( acl->value ) GACLfreeAcl(acl->value); + /* XXX if ( acl->value ) GRSTgaclAclFree(acl->value); */ if ( acl->string ) free(acl->string); free(acl); } @@ -799,7 +806,7 @@ int edg_wll_GetACL(edg_wll_Context ctx, edg_wlc_JobId jobid, edg_wll_Acl *acl) char *acl_str = NULL; edg_wll_Stmt stmt = NULL; int ret; - GACLacl *gacl = NULL; + GRSTgaclAcl *gacl = NULL; char *jobstr = edg_wlc_JobIdGetUnique(jobid); if (jobid == NULL || jobstr == NULL) @@ -852,7 +859,7 @@ end: if (stmt) edg_wll_FreeStmt(&stmt); if (acl_id) free(acl_id); if (acl_str) free(acl_str); - if (gacl) GACLfreeAcl(gacl); + if (gacl) GRSTgaclAclFree(gacl); if (jobstr) free(jobstr); return edg_wll_Error(ctx, NULL, NULL); diff --git a/org.glite.lb.server/src/lb_authz.h b/org.glite.lb.server/src/lb_authz.h index a23bd1b..0aa659a 100644 --- a/org.glite.lb.server/src/lb_authz.h +++ b/org.glite.lb.server/src/lb_authz.h @@ -2,12 +2,12 @@ #define LB_AUTHZ_H #ifndef NO_GACL -#include +#include #endif typedef struct _edg_wll_Acl { #ifndef NO_GACL - GACLacl *value; + GRSTgaclAcl *value; #else void *value; /* XXX */ #endif @@ -37,10 +37,10 @@ extern int edg_wll_CheckACL(edg_wll_Context, edg_wll_Acl, int); extern int -edg_wll_DecodeACL(char *, GACLacl **); +edg_wll_DecodeACL(char *, GRSTgaclAcl **); extern int -edg_wll_EncodeACL(GACLacl *, char **); +edg_wll_EncodeACL(GRSTgaclAcl *, char **); extern int edg_wll_GetACL(edg_wll_Context, edg_wlc_JobId, edg_wll_Acl *); diff --git a/org.glite.lb.server/src/lb_proto.c b/org.glite.lb.server/src/lb_proto.c index 4ab0453..582c41b 100644 --- a/org.glite.lb.server/src/lb_proto.c +++ b/org.glite.lb.server/src/lb_proto.c @@ -633,6 +633,8 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, else if (!strncmp(requestPTR,KEY_PURGE_REQUEST,sizeof(KEY_PURGE_REQUEST)-1)) { edg_wll_PurgeRequest request; + ctx->p_tmp_timeout.tv_sec = 86400; + if ( !parsePurgeRequest(ctx,messageBody,(int (*)()) edg_wll_StringToStat,&request) ) edg_wll_PurgeServer(ctx, (const edg_wll_PurgeRequest *)&request); @@ -656,6 +658,8 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, edg_wll_DumpRequest request; edg_wll_DumpResult result; + ctx->p_tmp_timeout.tv_sec = 86400; + memset(&request,0,sizeof(request)); memset(&result,0,sizeof(result)); @@ -686,6 +690,8 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, edg_wll_LoadRequest request; edg_wll_LoadResult result; + ctx->p_tmp_timeout.tv_sec = 86400; + memset(&request,0,sizeof(request)); memset(&result,0,sizeof(result)); diff --git a/org.glite.lb.server/src/lbs_db.c b/org.glite.lb.server/src/lbs_db.c index ebe6362..16df6c9 100644 --- a/org.glite.lb.server/src/lbs_db.c +++ b/org.glite.lb.server/src/lbs_db.c @@ -53,7 +53,10 @@ edg_wll_ErrorCode edg_wll_DBConnect(edg_wll_Context ctx,char *cs) pw = slash+1; db = colon+1; - if (!mysql_real_connect((MYSQL *) ctx->mysql,host,user,pw,db,0,NULL,0)) { + /* ljocha: CLIENT_FOUND_ROWS added to make authorization check + * working in update_notif(). + * Hope it does not break anything else */ + if (!mysql_real_connect((MYSQL *) ctx->mysql,host,user,pw,db,0,NULL,CLIENT_FOUND_ROWS)) { free(buf); return my_err(); } diff --git a/org.glite.lb.server/src/notification.c b/org.glite.lb.server/src/notification.c index 048176e..5c88757 100644 --- a/org.glite.lb.server/src/notification.c +++ b/org.glite.lb.server/src/notification.c @@ -11,9 +11,13 @@ #include "lbs_db.h" -static char *get_user(edg_wll_Context ctx, int create); -static int update_notif(edg_wll_Context, const edg_wll_NotifId, - const char *, const char *, const char *); +static char *get_user(edg_wll_Context ctx, int create); +static int check_notif_request(edg_wll_Context, const edg_wll_NotifId, char **); +static int split_cond_list(edg_wll_Context, edg_wll_QueryRec const * const *, + edg_wll_QueryRec ***, char ***); +static int update_notif(edg_wll_Context, const edg_wll_NotifId, + const char *, const char *, const char *); + int edg_wll_NotifNewServer( edg_wll_Context ctx, @@ -22,9 +26,7 @@ int edg_wll_NotifNewServer( const edg_wll_NotifId nid, time_t *valid) { - int i, j, - ct, - new_rows; + int i; char *q = NULL, *nid_s = NULL, *time_s = NULL, @@ -46,47 +48,15 @@ int edg_wll_NotifNewServer( goto cleanup; /* Format conditions - * - first of all separate all jobids - * - then format new condition list without jobids and encode it into an XML string + * - separate all jobids + * - format new condition list without jobids */ - if ( !conditions || !conditions[0] ) - { - edg_wll_SetError(ctx, EINVAL, "Empty condition list"); + if ( split_cond_list(ctx, conditions, &nconds, &jobs) ) goto cleanup; - } - for ( new_rows = ct = i = 0; conditions[i]; i++ ) - { - if ( conditions[i][0].attr && conditions[i][0].attr != EDG_WLL_QUERY_ATTR_JOBID ) - new_rows++; - for ( j = 0; conditions[i][j].attr; j++ ) - if ( conditions[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID ) - ct++; - } - if ( !ct ) - { - edg_wll_SetError(ctx, EINVAL, "Notification has to bind to at least one jobID"); - goto cleanup; - } - if ( !(jobs = calloc(ct+1, sizeof(char *))) - || !(nconds = calloc(new_rows+1, sizeof(edg_wll_QueryRec *))) ) - { - edg_wll_SetError(ctx, errno, NULL); - goto cleanup; - } - for ( ct = i = 0; conditions[i]; i++ ) - for ( j = 0; conditions[i][j].attr; j++ ) - if ( conditions[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID ) - if ( !(jobs[ct++] = edg_wlc_JobIdGetUnique(conditions[i][j].value.j)) ) - { - edg_wll_SetError(ctx, errno, NULL); - goto cleanup; - } - for ( new_rows = i = 0; conditions[i]; i++ ) - if ( conditions[i][0].attr && conditions[i][0].attr != EDG_WLL_QUERY_ATTR_JOBID ) - /* !!! DO NOT DEALLOCATE this arrays (it is not neccessary to allocate new - * mem - it's used only once and only for xml parsing - */ - nconds[new_rows++] = (edg_wll_QueryRec *) (conditions[i]); + + /* + * encode new cond. list into a XML string + */ if ( edg_wll_JobQueryRecToXML(ctx, (edg_wll_QueryRec const * const *) nconds, &xml_conds) ) { /* XXX: edg_wll_JobQueryRecToXML() do not set errors in context! @@ -184,7 +154,8 @@ int edg_wll_NotifBindServer( const char *address_override, time_t *valid) { - char *time_s = NULL; + char *time_s = NULL, + *addr_s = NULL; if ( !address_override ) @@ -193,6 +164,9 @@ int edg_wll_NotifBindServer( goto cleanup; } + if ( check_notif_request(ctx, nid, NULL) ) + goto cleanup; + /* Format time of validity */ *valid = time(NULL); @@ -209,21 +183,133 @@ int edg_wll_NotifBindServer( } time_s[strlen(time_s)-1] = 0; - update_notif(ctx, nid, NULL, address_override, (const char *)(time_s+1)); + /* Format the address + */ + if ( address_override ) + { + char *aux; + + if ( !(aux = strchr(address_override, ':')) ) + { + edg_wll_SetError(ctx, EINVAL, "Addres overrirde not in format host:port"); + goto cleanup; + } + if ( !strncmp(address_override, "0.0.0.0", aux-address_override) ) + trio_asprintf(&addr_s, "%s:%s", ctx->connPool[ctx->connToUse].peerName, aux+1); + } + + + update_notif(ctx, nid, NULL, addr_s? addr_s: address_override, (const char *)(time_s+1)); cleanup: if ( time_s ) free(time_s); + if ( addr_s ) free(addr_s); return edg_wll_Error(ctx, NULL, NULL); } + int edg_wll_NotifChangeServer( edg_wll_Context ctx, - const edg_wll_NotifId id, + const edg_wll_NotifId nid, edg_wll_QueryRec const * const *conditions, edg_wll_NotifChangeOp op) { - return edg_wll_SetError(ctx, EINVAL, "Not yet implemented"); + int i; + char *q = NULL, + *nid_s = NULL, + *xml_conds = NULL, + **jobs = NULL; + edg_wll_QueryRec **nconds = NULL; + + + /* Format notification ID + */ + if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) ) + goto cleanup; + + if ( check_notif_request(ctx, nid, NULL) ) + goto cleanup; + + switch ( op ) + { + case EDG_WLL_NOTIF_REPLACE: + /* Format conditions + * - separate all jobids + * - format new condition list without jobids + */ + if ( split_cond_list(ctx, conditions, &nconds, &jobs) ) + goto cleanup; + + /* + * encode new cond. list into a XML string + */ + if ( edg_wll_JobQueryRecToXML(ctx, (edg_wll_QueryRec const * const *) nconds, &xml_conds) ) + { + /* XXX: edg_wll_JobQueryRecToXML() do not set errors in context! + * can't get propper error number :( + */ + edg_wll_SetError(ctx, errno, "Can't encode data into xml"); + goto cleanup; + } + + /* Format DB insert statement + */ + if ( update_notif(ctx, nid, xml_conds, NULL, NULL) ) + goto cleanup; + + if ( jobs ) + { + /* Format DB insert statement + */ + trio_asprintf(&q, "delete from notif_jobs where notifid='%|Ss'", nid_s); + if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 ) + goto cleanup; + + for ( i = 0; jobs[i]; i++ ) + { + free(q); + trio_asprintf(&q, + "insert into notif_jobs(notifid,jobid) values ('%|Ss','%|Ss')", + nid_s, jobs[i]); + if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 ) + { + /* XXX: Remove uncoplete registration? + * Which error has to be returned? + */ + free(q); + trio_asprintf(&q, "delete from notif_jobs where notifid='%|Ss'", nid_s); + edg_wll_ExecStmt(ctx, q, NULL); + free(q); + trio_asprintf(&q,"delete from notif_registrations where notifid='%|Ss'", nid_s); + edg_wll_ExecStmt(ctx, q, NULL); + goto cleanup; + } + } + } + break; + + case EDG_WLL_NOTIF_ADD: + break; + case EDG_WLL_NOTIF_REMOVE: + break; + default: + break; + } + +cleanup: + if ( q ) free(q); + if ( xml_conds ) free(xml_conds); + if ( nid_s ) free(nid_s); + if ( jobs ) + { + for ( i = 0; jobs[i]; i++ ) + free(jobs[i]); + free(jobs); + } + if ( nconds ) free(nconds); + + return edg_wll_Error(ctx, NULL, NULL); } int edg_wll_NotifRefreshServer( @@ -234,6 +320,9 @@ int edg_wll_NotifRefreshServer( char *time_s = NULL; + if ( check_notif_request(ctx, nid, NULL) ) + goto cleanup; + /* Format time of validity */ *valid = time(NULL); @@ -262,54 +351,32 @@ int edg_wll_NotifDropServer( edg_wll_Context ctx, edg_wll_NotifId *nid) { - char *owner = NULL, - *nid_s = NULL, + char *nid_s = NULL, *stmt; int ret; - if ( !(owner = get_user(ctx, 0)) ) - { - if ( !edg_wll_Error(ctx, NULL, NULL) ) - edg_wll_SetError(ctx, EPERM, "Unknown user"); - - return edg_wll_Error(ctx, NULL, NULL); - } + if ( check_notif_request(ctx, nid, NULL) ) + goto cleanup; if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) ) goto cleanup; - /* Only the owner could remove the notification registration - */ - trio_asprintf(&stmt, - "delete from notif_registrations where notifid='%|Ss' and userid='%|Ss'", - nid_s, owner); + trio_asprintf(&stmt, "delete from notif_registrations where notifid='%|Ss'", nid_s); if ( (ret = edg_wll_ExecStmt(ctx, stmt, NULL)) < 0 ) goto cleanup; free(stmt); - if ( ret == 0 ) - { - trio_asprintf(&stmt, - "select notifid from notif_registrations where notifid='%|Ss'", nid_s); - ret = edg_wll_ExecStmt(ctx, stmt, NULL); - if ( ret == 0 ) - edg_wll_SetError(ctx, ENOENT, "Unknown notification ID"); - else if ( ret > 0 ) - edg_wll_SetError(ctx, EPERM, NULL); - - goto cleanup; - } trio_asprintf(&stmt, "delete from notif_jobs where notifid='%|Ss'", nid_s); edg_wll_ExecStmt(ctx, stmt, NULL); cleanup: - if ( owner ) free(owner); if ( nid_s ) free(nid_s); if ( stmt ) free(stmt); return edg_wll_Error(ctx, NULL, NULL); } + static char *get_user(edg_wll_Context ctx, int create) { edg_wll_Stmt stmt = NULL; @@ -320,7 +387,7 @@ static char *get_user(edg_wll_Context ctx, int create) if ( !ctx->peerName ) { - edg_wll_SetError(ctx, EPERM, "Annonymous notifications not allowed"); + edg_wll_SetError(ctx, EPERM, "Annonymous access not allowed"); goto cleanup; } trio_asprintf(&q, "select userid from users where cert_subj='%|Ss'", ctx->peerName); @@ -361,20 +428,18 @@ cleanup: return userid; } -static int update_notif( - edg_wll_Context ctx, - const edg_wll_NotifId nid, - const char *conds, - const char *dest, - const char *valid) + +static int check_notif_request( + edg_wll_Context ctx, + const edg_wll_NotifId nid, + char **owner) { - char *owner = NULL, - *nid_s = NULL, - *stmt, *aux; + char *nid_s = NULL, + *stmt, *user; int ret; - if ( !(owner = get_user(ctx, 0)) ) + if ( !(user = get_user(ctx, 0)) ) { if ( !edg_wll_Error(ctx, NULL, NULL) ) edg_wll_SetError(ctx, EPERM, "Unknown user"); @@ -385,10 +450,133 @@ static int update_notif( if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) ) goto cleanup; + trio_asprintf(&stmt, + "select notifid from notif_registrations " + "where notifid='%|Ss' and userid='%|Ss'", + nid_s, user); + + if ( (ret = edg_wll_ExecStmt(ctx, stmt, NULL)) < 0 ) + goto cleanup; + if ( ret == 0 ) + { + free(stmt); + trio_asprintf(&stmt, + "select notifid from notif_registrations where notifid='%|Ss'", nid_s); + ret = edg_wll_ExecStmt(ctx, stmt, NULL); + if ( ret == 0 ) + edg_wll_SetError(ctx, ENOENT, "Unknown notification ID"); + else if ( ret > 0 ) + edg_wll_SetError(ctx, EPERM, "Only owner could access the notification"); + } + +cleanup: + if ( !edg_wll_Error(ctx, NULL, NULL) && owner ) + *owner = user; + else + free(user); + if ( nid_s ) free(nid_s); + if ( stmt ) free(stmt); + + return edg_wll_Error(ctx, NULL, NULL); +} + + + /* Format conditions + * - first of all separate all jobids + * - then format new condition list without jobids and encode it into an XML string + */ +static int split_cond_list( + edg_wll_Context ctx, + edg_wll_QueryRec const * const *conditions, + edg_wll_QueryRec ***nconds_out, + char ***jobs_out) +{ + edg_wll_QueryRec **nconds = NULL; + char **jobs = NULL; + int i, j, jobs_ct, nconds_ct; + + + if ( !conditions || !conditions[0] ) + return edg_wll_SetError(ctx, EINVAL, "Empty condition list"); + + for ( nconds_ct = jobs_ct = i = 0; conditions[i]; i++ ) + { + if ( conditions[i][0].attr && conditions[i][0].attr != EDG_WLL_QUERY_ATTR_JOBID ) + nconds_ct++; + for ( j = 0; conditions[i][j].attr; j++ ) + if ( conditions[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID ) + jobs_ct++; + } + + if ( jobs_out && jobs_ct ) + if ( !(jobs = calloc(jobs_ct+1, sizeof(char *))) ) + { + edg_wll_SetError(ctx, errno, NULL); + goto cleanup; + } + + if ( nconds_out && nconds_ct ) + if ( !(nconds = calloc(nconds_ct+1, sizeof(edg_wll_QueryRec *))) ) + { + edg_wll_SetError(ctx, errno, NULL); + goto cleanup; + } + + if ( jobs ) for ( jobs_ct = i = 0; conditions[i]; i++ ) + for ( j = 0; conditions[i][j].attr; j++ ) + if ( conditions[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID ) + if ( !(jobs[jobs_ct++] = edg_wlc_JobIdGetUnique(conditions[i][j].value.j)) ) + { + edg_wll_SetError(ctx, errno, NULL); + goto cleanup; + } + + if ( nconds ) for ( nconds_ct = i = 0; conditions[i]; i++ ) + if ( conditions[i][0].attr && conditions[i][0].attr != EDG_WLL_QUERY_ATTR_JOBID ) + /* !!! DO NOT DEALLOCATE this arrays (it is not neccessary to allocate new + * mem - it's used only once and only for xml parsing + */ + nconds[nconds_ct++] = (edg_wll_QueryRec *) (conditions[i]); + + if ( jobs_out ) { *jobs_out = jobs; jobs = NULL; } + if ( nconds_out ) { *nconds_out = nconds; nconds = NULL; } + +cleanup: + if ( nconds ) free(nconds); + if ( jobs ) + { + for ( i = 0; jobs[i]; i++ ) + free(jobs[i]); + free(jobs); + } + + return edg_wll_Error(ctx, NULL, NULL); +} + + +static int update_notif( + edg_wll_Context ctx, + const edg_wll_NotifId nid, + const char *conds, + const char *dest, + const char *valid) +{ + char *nid_s = NULL, + *stmt, *aux; + int ret; + + + if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) ) + goto cleanup; + /* Format SQL update string * (Only the owner could update the notification registration) */ - stmt = strdup("update notif_registrations set"); + if ( !(stmt = strdup("update notif_registrations set")) ) + { + edg_wll_SetError(ctx, errno, "updating notification records"); + goto cleanup; + } if ( dest ) { trio_asprintf(&aux, "%s destination='%|Ss'", stmt, dest); @@ -403,13 +591,12 @@ static int update_notif( } if ( conds ) { - trio_asprintf(&aux, "%s %sconditions='%|Ss'", + trio_asprintf(&aux, "%s %sconditions='%|Ss'", stmt, (dest||valid)? ",": "", conds); free(stmt); stmt = aux; } - trio_asprintf(&aux, "%s where notifid='%|Ss' and userid='%|Ss'", - stmt, nid_s, owner); + trio_asprintf(&aux, "%s where notifid='%|Ss'", stmt, nid_s); free(stmt); stmt = aux; @@ -423,14 +610,19 @@ static int update_notif( ret = edg_wll_ExecStmt(ctx, stmt, NULL); if ( ret == 0 ) edg_wll_SetError(ctx, ENOENT, "Unknown notification ID"); + /* + * XXX: Be happy? + * May be: Rows matched: 1 Changed: 0 Warnings: 0 :-) else if ( ret > 0 ) edg_wll_SetError(ctx, EPERM, "Updating notification records"); + */ } cleanup: - if ( owner ) free(owner); if ( nid_s ) free(nid_s); if ( stmt ) free(stmt); return edg_wll_Error(ctx, NULL, NULL); } + + diff --git a/org.glite.lb.server/test/oneJob.qry b/org.glite.lb.server/test/oneJob.qry new file mode 100644 index 0000000..d419ce8 --- /dev/null +++ b/org.glite.lb.server/test/oneJob.qry @@ -0,0 +1,24 @@ +SELECT e.event,j.userid,j.dg_jobid,e.code,e.prog,e.host,u.cert_subj,e.time_stamp,e.usec,e.level,e.arrived FROM events e,users u,jobs j WHERE e.jobid=j.jobid AND e.userid=u.userid AND e.code != 0 AND (j.jobid='WrCEKje9QTXFiSOZuPMLtw') +0 294de3557d9d00b3d2d8a1e6aab028cf https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw 17 UserInterface lhun.ics.muni.cz anonymous 2003-08-07 11:08:40 432100 8 2003-08-07 11:08:40 +1 294de3557d9d00b3d2d8a1e6aab028cf https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw 2 NetworkServer lhun.ics.muni.cz anonymous 2003-08-07 11:09:05 664600 8 2003-08-07 11:09:05 + +select name,value from short_fields where jobid = 'WrCEKje9QTXFiSOZuPMLtw' and event = 0 +JDL x +JOBTYPE SIMPLE +NS NNNSSSS +NSUBJOBS 0 +PARENT https://lhun.ics.muni.cz:4850/Qt7utj80miXexi7bkxyhnA +SEQCODE (nil) +SRC_INSTANCE (nil) + +select name,value from long_fields where jobid = 'WrCEKje9QTXFiSOZuPMLtw' and event = 0 + +select name,value from short_fields where jobid = 'WrCEKje9QTXFiSOZuPMLtw' and event = 1 +FROM UserInterface +FROM_HOST sending component hostname +FROM_INSTANCE sending component instance +LOCAL_JOBID new jobId (Condor Globus ...) +SEQCODE UI=000002:NS=0000000001:WM=000000:BH=0000000000:JSS=000000:LM=000000:LRMS=000000:APP=000000 +SRC_INSTANCE + +select name,value from long_fields where jobid = 'WrCEKje9QTXFiSOZuPMLtw' and event = 1 diff --git a/org.glite.lb.server/test/test_query_events.cpp b/org.glite.lb.server/test/test_query_events.cpp new file mode 100644 index 0000000..bf356f4 --- /dev/null +++ b/org.glite.lb.server/test/test_query_events.cpp @@ -0,0 +1,152 @@ +#include + +#include +#include +#include +#include + +#include +#include + +#include "lbs_db.h" +#include "get_events.h" + +using namespace std; + +static const char *test_dir; + +class QueryEventsTest: public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(QueryEventsTest); + CPPUNIT_TEST(oneJob); + CPPUNIT_TEST_SUITE_END(); + +private: + edg_wll_Context ctx; + + ifstream qry_file; + + vector > > queries; + +public: + void oneJob(); + int ExecStmt(const char *, edg_wll_Stmt *); + + void setUp() { + edg_wll_InitContext(&ctx); + ctx->mysql = (void *) this; /* XXX */ + } + +}; + +void QueryEventsTest::oneJob() +{ + edg_wll_QueryRec job[2]; + const edg_wll_QueryRec *jobs[2] = { job,NULL} ; + edg_wll_Event *events; + + job[0].attr = EDG_WLL_QUERY_ATTR_JOBID; + job[0].op = EDG_WLL_QUERY_OP_EQUAL ; + edg_wlc_JobIdParse("https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw", + &job[0].value.j); + job[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; + + string file(test_dir); + file += "/oneJob.qry"; + qry_file.open(file.c_str()); + + while (!qry_file.eof()) { + string query,line; + vector rows; + + getline(qry_file,query); + cout << "read: " << query < >(query,rows)); + } + + qry_file.close(); + + CPPUNIT_ASSERT(!edg_wll_QueryEventsServer(ctx,1,jobs,NULL,&events)); +} + +int QueryEventsTest::ExecStmt(const char *qry, edg_wll_Stmt *stmt_out) +{ + vector > >::iterator stmt = queries.begin(); + + for (; stmt != queries.end(); stmt++) { + const char *q = stmt->first.c_str(); + + /* XXX: there some spaces at the end of qry */ + if (!strncmp(q,qry,strlen(q))) break; + } + + if (stmt == queries.end()) { + cerr << "query not found" << endl; + CPPUNIT_ASSERT(0); + } + vector::iterator *rows = new vector::iterator(stmt->second.begin()); + + *stmt_out = (edg_wll_Stmt) rows; + return stmt->second.size()-1; +} + +extern "C" { + +int edg_wll_ExecStmt(edg_wll_Context ctx,char *qry,edg_wll_Stmt *stmt) +{ + cout << "edg_wll_ExecStmt: " << qry << endl; + + class QueryEventsTest *tst = (class QueryEventsTest *)(ctx->mysql); + return tst->ExecStmt(qry, stmt); +} + +int edg_wll_FetchRow(edg_wll_Stmt stmt, char **cols) +{ + vector::iterator *rows = (vector::iterator *) stmt; + char *row,*p,i=0; + + if (**rows == "END") return 0; + row = strdup((*rows)->c_str()); + (*rows)++; + for (p = strtok(row,"\t"); p; p = strtok(NULL,"\t")) + cols[i++] = strdup(p); + + return i; +} + +void edg_wll_FreeStmt(edg_wll_Stmt *) {} + +int debug; + +int edg_wll_QueryColumns(edg_wll_Stmt stmt, char**cols) {} +char *edg_wll_TimeToDB(long t) {} + +time_t edg_wll_DBToTime(char *c) {} +edg_wll_ErrorCode edg_wll_DBConnect(edg_wll_Context ctx, char*str) {} + + + + +} + +CPPUNIT_TEST_SUITE_REGISTRATION(QueryEventsTest); + +int main (int ac,const char *av[]) +{ + CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); + CppUnit::TextUi::TestRunner runner; + + test_dir = ac >= 2 ? av[1] : "../test"; + + runner.addTest(suite); + return runner.run() ? 0 : 1; +} -- 1.8.2.3