/[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 1352 - (show annotations) (download) (as text)
Fri Jan 8 17:32:05 2010 UTC (12 years ago) by aramv
File MIME type: text/x-chdr
File size: 2563 byte(s)
Hunted memleaks in the new AOS - making progress slowly
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 aos_attribute_t* pemstring;
12 aos_context_t* context;
13
14 EES_PL_RC plugin_initialize(int argc, char* argv[]){
15 char *cert_file_name = "/.globus/usercert.pem";
16 char *home = "";
17 struct stat _stat;
18 /* get home dir */
19 home = getenv("HOME");
20 if((cert_file = calloc(1, (sizeof(char) * (strlen(home) + strlen(cert_file_name) + 1))))){
21 strcat(cert_file, home);
22 strcat(cert_file, cert_file_name);
23 } else {
24 eef_log(LOG_ERR, "Out of memory!\n");
25 return EES_PL_FAILURE;
26 }
27
28 eef_log(LOG_ERR, "Initializing example plugin!\n");
29 if((_fd = open(cert_file, O_RDONLY)) == -1){
30 eef_log(LOG_ERR, "Cannot open file %s: %s\n", cert_file, strerror(errno));
31 }
32
33 if(fstat(_fd, &_stat) == -1){
34 eef_log(LOG_ERR, "Cannot stat file %s: %s\n", cert_file, strerror(errno));
35 return EES_PL_FAILURE;
36 }
37
38 if(!(_string = calloc(1, (_stat.st_size+1)*sizeof(char)))){
39 eef_log(LOG_ERR, "Out of memory!");
40 return EES_PL_FAILURE;
41 }
42
43
44 if((read(_fd, _string, _stat.st_size)) == -1){
45 eef_log(LOG_ERR, "Cannot read file %s\n", cert_file);
46 return EES_PL_FAILURE;
47 } else {
48 #ifdef HAVE_LONG_LONG_INT
49 printf("Read %lld bytes from file '%s'\n", (long long int) _stat.st_size, cert_file);
50 #else
51 printf("Read %ld bytes from file '%s'\n", (long int) _stat.st_size, cert_file);
52 #endif
53 /*setObligation("my_pemstring", _string);*/
54 /*pemstring = createAttribute();*/
55 /*setAttributeId(pemstring, "my_pemstring");*/
56 /*setAttributeValue(pemstring, _string, strlen(_string));*/
57 /*if((context = getNextContext(ANY, NULL)) == NULL){*/
58 /*context = createContext(ANY);*/
59 /*}*/
60 /*addAttribute(context, pemstring);*/
61 return EES_PL_SUCCESS;
62 }
63
64 return EES_PL_FAILURE;
65 }
66
67 EES_PL_RC plugin_run(){
68 eef_log(LOG_ERR, "Getting 'pemstring'\n");
69 /*context = getNextContext(ANY,NULL);*/
70 /*while(pemstring = getNextAttribute(context)){*/
71 /*if(getAttributeId(pemstring) == "my_pemstring"){*/
72 /*eef_log(LOG_ERR, "my_pemstring: %s\n", getObligation("my_pemstring"));*/
73 /*}*/
74 /*}*/
75
76 eef_log(LOG_ERR, "Setting 'pemstring' leeg\n");
77 /*setObligation("my_pemstring", "Leeggehaald\n");*/
78 /*setObligation("foo", "barbaz");*/
79 return EES_PL_SUCCESS;
80 }
81
82 EES_PL_RC plugin_terminate(){
83 /*destroyObligation("my_pemstring");*/
84 free(cert_file);
85 if(_fd > 0){
86 close(_fd);
87 free(_string);
88 }
89 return EES_PL_SUCCESS;
90 }

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