~ubuntu-branches/ubuntu/saucy/lcmaps-plugins-jobrep/saucy

« back to all changes in this revision

Viewing changes to src/jobrep/jobrep_data_handling.c

  • Committer: Package Import Robot
  • Author(s): Dennis van Dok
  • Date: 2013-05-23 11:38:59 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130523113859-j3aprq5imdokjunw
Tags: 1.5.3-1
New upstream release ; this includes recording the GATEKEEPER_JM_ID
so jobs can be linked to credentials

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    return 0;
28
28
}
29
29
 
30
 
int
 
30
long
31
31
jobrep_assign_userid(struct jr_db_handle_s *db_handle, STACK_OF(X509) *px509_chain, char *eec_subject_dn) {
32
 
    int user_id = -1, cert_id = -1;
 
32
    long user_id = -1;
 
33
    long cert_id = -1;
33
34
    int i = 0, depth = 0;
34
35
    int found = 0;
35
36
    char *subject_DN = NULL, *issuer_DN = NULL;
214
215
    return -1;
215
216
}
216
217
 
217
 
int
 
218
long
218
219
jobrep_get_voms_fqan_id_from_fqan(struct jr_db_handle_s *db_handle, char *voms_fqan) {
219
 
    int voms_fqan_id = -1;
 
220
    long voms_fqan_id = -1;
 
221
    SQLRETURN ret;
220
222
 
221
223
    if ((db_handle == NULL) || (voms_fqan == NULL)) {
222
224
        return -1;
233
235
        goto fail_jobrep;
234
236
    }
235
237
    /* The VOMS FQAN must exist in the database! */
236
 
    if (SQL_Query(db_handle) < 0) {
 
238
    ret=SQL_Query(db_handle);
 
239
    if (!SQL_SUCCEEDED(ret)) {
237
240
        lcmaps_log(LOG_ERR, "%s: Failed to execute the query to fetch the voms_fqan_id from the voms_fqans.\n", __func__);
238
241
        goto fail_jobrep;
239
242
    }
263
266
    return voms_fqan_id;
264
267
}
265
268
 
 
269
/* Next function is not used, commenting out */
 
270
#if 0
266
271
int
267
272
jobrep_get_unix_uid_id_from_uid(struct jr_db_handle_s *db_handle, uid_t uid, char *uid_name) {
268
 
    int unix_uid_id = -1;
 
273
    long unix_uid_id = -1;
 
274
    SQLRETURN ret;
269
275
 
270
 
    if ((db_handle == NULL) || (uid < 0)) {
 
276
    if (db_handle == NULL) {
271
277
        return -1;
272
278
    }
273
279
 
292
298
        }
293
299
    }
294
300
    /* The (Unix) UID must exist in the database! */
295
 
    if (SQL_Query(db_handle) < 0) {
 
301
    ret=SQL_Query(db_handle);
 
302
    if (!SQL_SUCCEEDED(ret)) {
296
303
        lcmaps_log(LOG_ERR, "%s: Failed to execute the query to fetch the unix_uid_id from the unix_uids.\n", __func__);
297
304
        goto fail_jobrep;
298
305
    }
321
328
    SQL_QueryCloseAndClean(db_handle);
322
329
    return unix_uid_id;
323
330
}
 
331
#endif
324
332
 
325
 
int
 
333
long
326
334
jobrep_get_unix_gid_id_from_gid(struct jr_db_handle_s *db_handle, gid_t gid, char *gid_name) {
327
 
    int unix_gid_id = -1;
 
335
    long unix_gid_id = -1;
 
336
    SQLRETURN ret;
328
337
 
329
 
    if ((db_handle == NULL) || (gid < 0)) {
 
338
    if (db_handle == NULL) {
330
339
        return -1;
331
340
    }
332
341
 
351
360
        }
352
361
    }
353
362
    /* The (Unix) GID must exist in the database! */
354
 
    if (SQL_Query(db_handle) < 0) {
 
363
    ret=SQL_Query(db_handle);
 
364
    if (!SQL_SUCCEEDED(ret)) {
355
365
        lcmaps_log(LOG_ERR, "%s: Failed to execute the query to fetch the unix_gid_id from the unix_gids.\n", __func__);
356
366
        goto fail_jobrep;
357
367
    }
381
391
    return unix_gid_id;
382
392
}
383
393
 
384
 
int
385
 
jobrep_insert_unix_uid_voms_fqans(struct jr_db_handle_s *db_handle, int voms_fqan_id, int unix_uid_id) {
 
394
long
 
395
jobrep_insert_unix_uid_voms_fqans(struct jr_db_handle_s *db_handle, long voms_fqan_id, long unix_uid_id) {
386
396
    char                *reg_datetime = NULL;
387
 
    int                  unix_uid_voms_fqan_id = -1;
 
397
    long                 unix_uid_voms_fqan_id = -1;
388
398
 
389
399
    if ((db_handle == NULL) || (voms_fqan_id < 0) || (unix_uid_id < 0)) {
390
400
        return -1;
463
473
    return -1;
464
474
}
465
475
 
466
 
int
467
 
jobrep_insert_unix_gid_voms_fqans(struct jr_db_handle_s *db_handle, int voms_fqan_id, int unix_gid_id, int is_primary) {
 
476
long
 
477
jobrep_insert_unix_gid_voms_fqans(struct jr_db_handle_s *db_handle, long voms_fqan_id, long unix_gid_id, int is_primary) {
468
478
    char                *reg_datetime = NULL;
469
 
    int                  unix_gid_voms_fqan_id = -1;
 
479
    long                  unix_gid_voms_fqan_id = -1;
470
480
 
471
481
    if ((db_handle == NULL) || (voms_fqan_id < 0) || (unix_gid_id < 0)) {
472
482
        return -1;
553
563
    return -1;
554
564
}
555
565
 
556
 
int
 
566
long
557
567
jobrep_create_effective_credentials_main(struct jr_db_handle_s *db_handle) {
558
568
    char *reg_datetime = NULL;
559
 
    int   eff_cred_id = -1;
 
569
    long eff_cred_id = -1;
560
570
 
561
571
    /*** Insert the effective_credentials ***/
562
572
    if (SQL_Prepare(db_handle,
615
625
}
616
626
 
617
627
int
618
 
jobrep_push_voms_fqans(struct jr_db_handle_s *db_handle, int eff_cred_id) {
 
628
jobrep_push_compute_job_info(struct jr_db_handle_s *db_handle, long eff_cred_id, char *gatekeeper_jm_id) {
 
629
    if (db_handle == NULL || eff_cred_id == -1 || gatekeeper_jm_id == NULL) {
 
630
        return -1;
 
631
    }
 
632
 
 
633
    /*** Insert the effective_credentials ***/
 
634
    if (SQL_Prepare(db_handle,
 
635
            (unsigned char *)"insert into compute_jobs (eff_cred_id, gatekeeper_jm_id) values (?, ?)") < 0) {
 
636
        lcmaps_log(LOG_ERR, "%s: Failed to prepare a query to insert a compute_jobs record into \"compute_jobs\"\n", __func__);
 
637
        goto fail_jobrep;
 
638
    }
 
639
 
 
640
    /* Bind data to Query */
 
641
    if (SQL_BindParam(db_handle, 1, SQL_C_LONG, SQL_INTEGER, &eff_cred_id) < 0) {
 
642
        lcmaps_log(LOG_ERR, "%s: Unable to bind the \"eff_cred_id\" value to the query\n", __func__);
 
643
        goto fail_jobrep;
 
644
    }
 
645
    if (SQL_BindParam(db_handle, 2, SQL_C_CHAR, SQL_VARCHAR, gatekeeper_jm_id) < 0) {
 
646
        lcmaps_log(LOG_ERR, "%s: Unable to bind the \"GATEKEEPER_JM_ID\" value to the query\n", __func__);
 
647
        goto fail_jobrep;
 
648
    }
 
649
 
 
650
    /* Fail on existance */
 
651
    SQL_Exec(db_handle);
 
652
 
 
653
    /* Clean up */
 
654
    SQL_QueryCloseAndClean(db_handle);
 
655
 
 
656
    return 0;
 
657
fail_jobrep:
 
658
    return -1;
 
659
}
 
660
 
 
661
int
 
662
jobrep_push_voms_fqans(struct jr_db_handle_s *db_handle, long eff_cred_id) {
619
663
    int                  i = 0;
620
664
    lcmaps_vo_mapping_t *vo_mapping = NULL;
621
665
    int                  cnt_vo_mapping = 0;
622
 
    int                  voms_fqan_id = -1;
623
 
    int                  unix_gid_id = -1;
 
666
    long                  voms_fqan_id = -1;
 
667
    long                  unix_gid_id = -1;
624
668
    int                  is_primary = 0;
625
 
    int                  unix_gid_voms_fqan_id = -1;
 
669
    long                  unix_gid_voms_fqan_id = -1;
626
670
 
627
671
    if (db_handle == NULL) {
628
672
        return -1;
705
749
}
706
750
 
707
751
int
708
 
jobrep_push_effective_credential_user(struct jr_db_handle_s *db_handle, int user_id, int eff_cred_id) {
 
752
jobrep_push_effective_credential_user(struct jr_db_handle_s *db_handle, long user_id, long eff_cred_id) {
709
753
    if ((db_handle == NULL) || (user_id < 0) || (eff_cred_id < 0)) {
710
754
        return -1;
711
755
    }
741
785
}
742
786
 
743
787
int
744
 
jobrep_push_effective_credential_unix_uid(struct jr_db_handle_s *db_handle, int unix_uid_id, int eff_cred_id) {
 
788
jobrep_push_effective_credential_unix_uid(struct jr_db_handle_s *db_handle, long unix_uid_id, long eff_cred_id) {
745
789
    int                  i = 0;
746
790
    lcmaps_vo_mapping_t *vo_mapping = NULL;
747
791
    int                  cnt_vo_mapping = 0;
748
 
    int                  voms_fqan_id = -1;
 
792
    long                  voms_fqan_id = -1;
749
793
    /* int                  unix_uid_id = -1; */
750
 
    int                  unix_uid_voms_fqan_id = -1;
 
794
    long                  unix_uid_voms_fqan_id = -1;
751
795
 
752
796
    if ((db_handle == NULL) || (unix_uid_id < 0) || (eff_cred_id < 0)) {
753
797
        return -1;
825
869
}
826
870
 
827
871
int
828
 
jobrep_push_effective_credential_unix_gid(struct jr_db_handle_s *db_handle, int unix_gid_id, int eff_cred_id, int is_primary) {
 
872
jobrep_push_effective_credential_unix_gid(struct jr_db_handle_s *db_handle, long unix_gid_id, long eff_cred_id, int is_primary) {
829
873
    if ((db_handle == NULL) || (unix_gid_id < 0) || (eff_cred_id < 0)) {
830
874
        return -1;
831
875
    }
865
909
}
866
910
 
867
911
int
868
 
jobrep_push_effective_credential_unix_gids(struct jr_db_handle_s *db_handle, int eff_cred_id) {
 
912
jobrep_push_effective_credential_unix_gids(struct jr_db_handle_s *db_handle, long eff_cred_id) {
869
913
    int                    i = 0;
870
914
    gid_t                 *priGid = NULL;
871
915
    int                    cntPriGid = 0;
872
916
    gid_t                 *secGid = NULL;
873
917
    int                    cntSecGid = 0;
874
918
    struct group          *group_info = NULL;
875
 
    int                    unix_gid_id = -1;
 
919
    long                    unix_gid_id = -1;
876
920
 
877
921
    if ((db_handle == NULL) || (eff_cred_id < 0)) {
878
922
        return -1;
927
971
    return -1;
928
972
}
929
973
 
930
 
int
 
974
long
931
975
jobrep_push_unix_cred(struct jr_db_handle_s *db_handle) {
932
976
    int                    i = 0;
933
 
    int                    unix_uid_id_and_res = -1;
 
977
    long                    unix_uid_id_and_res = -1;
934
978
    uid_t                 *uid = NULL;
935
979
    int                    cntUid = 0;
936
980
    gid_t                 *priGid = NULL;
1192
1236
    ASN1_INTEGER   *cert_Serial = NULL;
1193
1237
    unsigned char  *serialNumberDER = NULL, *temp = NULL, *serialStr = NULL;
1194
1238
    char           *subject_DN = NULL;
1195
 
    int             serialLen, len, j;
 
1239
    size_t          len;
 
1240
    int             j,serialLen;
1196
1241
 
1197
1242
    if (cert == NULL)
1198
1243
        return NULL;
1221
1266
        return NULL;
1222
1267
    }
1223
1268
 
1224
 
    temp = serialNumberDER = malloc(serialLen);
 
1269
    /* Note: serialLen is int and >0 */
 
1270
    temp = serialNumberDER = malloc((size_t)serialLen);
1225
1271
    if (serialNumberDER == NULL) {
1226
1272
        lcmaps_log(LOG_DEBUG, "%s: Could not allocate %d bytes\n", serialLen);
1227
1273
        return NULL;
1230
1276
    serialLen = i2c_ASN1_INTEGER(cert_Serial, &temp);
1231
1277
 
1232
1278
    /* Allocate as a Hex decimal + null-terminator */
1233
 
    len = serialLen * 2 + 1;
 
1279
    len = (size_t)serialLen * 2 + 1;
1234
1280
    serialStr = malloc(len);
1235
1281
    if (serialStr == NULL) {
1236
1282
        lcmaps_log(LOG_DEBUG, "%s: Could not allocate %d bytes\n", len);