/[pdpsoft]/trunk/grid-mw-security/ees/plugin_examples/example_plugin/src/example_plugin.c
ViewVC logotype

Contents of /trunk/grid-mw-security/ees/plugin_examples/example_plugin/src/example_plugin.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1267 - (show annotations) (download) (as text)
Wed Dec 9 16:41:47 2009 UTC (12 years, 9 months ago) by aramv
File MIME type: text/x-chdr
File size: 2020 byte(s)
Removed minor warnings
1 #include <unistd.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/stat.h>
5 #include <sys/fcntl.h>
6 #include "plugin.h"
7
8 static char *_string = NULL;
9 int _fd = 0;
10 char *cert_file = NULL;
11
12 EES_PL_RC plugin_initialize(int argc, char* argv[]){
13 char *cert_file_name = "/.globus/usercert.pem";
14 char *home = "";
15 struct stat _stat;
16
17 /* get home dir */
18 home = getenv("HOME");
19 if((cert_file = calloc(1, (sizeof(char) * (strlen(home) + strlen(cert_file_name) + 1))))){
20 strcat(cert_file, home);
21 strcat(cert_file, cert_file_name);
22 } else {
23 eef_log(LOG_ERR, "Out of memory!\n");
24 return EES_PL_FAILURE;
25 }
26
27 eef_log(LOG_ERR, "Initializing example plugin!\n");
28 if((_fd = open(cert_file, O_RDONLY)) == -1){
29 eef_log(LOG_ERR, "Cannot open file %s: %s\n", cert_file, strerror(errno));
30 }
31
32 if(fstat(_fd, &_stat) == -1){
33 eef_log(LOG_ERR, "Cannot stat file %s: %s\n", cert_file, strerror(errno));
34 return EES_PL_FAILURE;
35 }
36
37 if(!(_string = calloc(1, (_stat.st_size+1)*sizeof(char)))){
38 eef_log(LOG_ERR, "Out of memory!");
39 return EES_PL_FAILURE;
40 }
41
42
43 if((read(_fd, _string, _stat.st_size)) == -1){
44 eef_log(LOG_ERR, "Cannot read file %s\n", cert_file);
45 return EES_PL_FAILURE;
46 } else {
47 #ifdef HAVE_LONG_LONG_INT
48 printf("Read %lld bytes from file '%s'\n", (long long int) _stat.st_size, cert_file);
49 #else
50 printf("Read %ld bytes from file '%s'\n", (long int) _stat.st_size, cert_file);
51 #endif
52 setObligation("my_pemstring", _string);
53 return EES_PL_SUCCESS;
54 }
55
56 return EES_PL_FAILURE;
57 }
58
59 EES_PL_RC plugin_run(){
60 eef_log(LOG_ERR, "Getting 'pemstring'\n");
61 eef_log(LOG_ERR, "my_pemstring: %s\n", getObligation("my_pemstring"));
62 eef_log(LOG_ERR, "Setting 'pemstring' leeg\n");
63 setObligation("my_pemstring", "Leeggehaald\n");
64 setObligation("foo", "barbaz");
65 return EES_PL_SUCCESS;
66 }
67
68 EES_PL_RC plugin_terminate(){
69 destroyObligation("my_pemstring");
70 free(cert_file);
71 if(_fd > 0){
72 close(_fd);
73 free(_string);
74 }
75 return EES_PL_SUCCESS;
76 }

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28