/[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 1382 - (show annotations) (download) (as text)
Wed Jan 13 10:49:06 2010 UTC (12 years ago) by aramv
File MIME type: text/x-chdr
File size: 2886 byte(s)
Working on Posix enforcement plugin
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
58 /*if((context = getNextContext(ANY, NULL)) == NULL){*/
59 /*context = createContext(ANY);*/
60 /*addContext(context);*/
61 /*}*/
62
63 /*addAttribute(context, pemstring);*/
64 return EES_PL_SUCCESS;
65 }
66
67 return EES_PL_FAILURE;
68 }
69
70 EES_PL_RC plugin_run(){
71 eef_log(LOG_ERR, "Getting 'pemstring'\n");
72
73 pemstring = createAttribute();
74 setAttributeId(pemstring, "my_pemstring");
75 setAttributeValue(pemstring, _string, strlen(_string));
76
77 if((context = getNextContext(ANY, NULL)) == NULL){
78 context = createContext(ANY);
79 addContext(context);
80 }
81
82 addAttribute(context, pemstring);
83
84 /*context = getNextContext(ANY,NULL);*/
85 /*while(pemstring = getNextAttribute(context)){*/
86 /*if(getAttributeId(pemstring) == "my_pemstring"){*/
87 /*eef_log(LOG_ERR, "my_pemstring: %s\n", getObligation("my_pemstring"));*/
88 /*}*/
89 /*}*/
90
91 eef_log(LOG_ERR, "Setting 'pemstring' leeg\n");
92 /*setObligation("my_pemstring", "Leeggehaald\n");*/
93 /*setObligation("foo", "barbaz");*/
94 return EES_PL_SUCCESS;
95 }
96
97 EES_PL_RC plugin_terminate(){
98 /*destroyObligation("my_pemstring");*/
99 free(cert_file);
100 if(_fd > 0){
101 close(_fd);
102 free(_string);
103 }
104 return EES_PL_SUCCESS;
105 }

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