/[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 1225 - (show annotations) (download) (as text)
Thu Dec 3 13:51:19 2009 UTC (12 years, 1 month ago) by aramv
File MIME type: text/x-chdr
File size: 1719 byte(s)
Fixed a buf in file closing
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
11 EES_PL_RC plugin_initialize(int argc, char* argv[]){
12 char *cert_file = "~/.globus/usercert.pem";
13 /*char *cert_file = "/user/bla/.globus/usercert.pem";*/
14 struct stat _stat;
15 eef_log(LOG_ERR, "Initializing example plugin!\n");
16 if((_fd = open(cert_file, O_RDONLY)) == -1){
17 eef_log(LOG_ERR, "Cannot open file %s: %s\n", cert_file, strerror(errno));
18 }
19
20 if(fstat(_fd, &_stat) == -1){
21 eef_log(LOG_ERR, "Cannot stat file %s: %s\n", cert_file, strerror(errno));
22 return EES_PL_FAILURE;
23 }
24
25 if(!(_string = calloc(1, (_stat.st_size+1)*sizeof(char)))){
26 eef_log(LOG_ERR, "Out of memory!");
27 return EES_PL_FAILURE;
28 }
29
30
31 if((read(_fd, _string, _stat.st_size)) == -1){
32 eef_log(LOG_ERR, "Cannot read file %s\n", cert_file);
33 return EES_PL_FAILURE;
34 } else {
35 #ifdef HAVE_LONG_LONG_INT
36 printf("Read %lld bytes from file '%s'\n", (long long int) _stat.st_size, cert_file);
37 #else
38 printf("Read %ld bytes from file '%s'\n", (long int) _stat.st_size, cert_file);
39 #endif
40 setObligation("my_pemstring", _string);
41 return EES_PL_SUCCESS;
42 }
43
44 return EES_PL_FAILURE;
45 }
46
47 EES_PL_RC plugin_run(){
48 eef_log(LOG_ERR, "Getting 'pemstring'\n");
49 eef_log(LOG_ERR, "my_pemstring: %s\n", getObligation("my_pemstring"));
50 eef_log(LOG_ERR, "Setting 'pemstring' leeg\n");
51 setObligation("my_pemstring", "Leeggehaald\n");
52 setObligation("foo", "barbaz");
53 return EES_PL_SUCCESS;
54 }
55
56 EES_PL_RC plugin_terminate(){
57 destroyObligation("my_pemstring");
58 if(_fd > 0){
59 close(_fd);
60 free(_string);
61 }
62 return EES_PL_SUCCESS;
63 }

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