/[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 1583 - (show annotations) (download) (as text)
Fri Mar 19 17:29:41 2010 UTC (12 years, 6 months ago) by aramv
File MIME type: text/x-chdr
File size: 2977 byte(s)
Fixed a read error. Added signature for fork function
1 #include <unistd.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/stat.h>
5 #include <sys/fcntl.h>
6 #include "eef_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 aos_attribute_t *_uid, *_gid;
14 char* _uid_str = "1000";
15 char* _gid_str = "1000";
16
17 EES_PL_RC plugin_initialize(int argc, char* argv[]){
18 char *cert_file_name = "/.globus/usercert.pem";
19 char *home = "";
20 struct stat _stat;
21 /* get home dir */
22 home = getenv("HOME");
23 if((cert_file = calloc(1, (sizeof(char) * (strlen(home) + strlen(cert_file_name) + 1))))){
24 strcat(cert_file, home);
25 strcat(cert_file, cert_file_name);
26 } else {
27 eef_log(LOG_ERR, "Out of memory!\n");
28 return EES_PL_FAILURE;
29 }
30
31 eef_log(LOG_ERR, "Initializing example plugin!\n");
32 if((_fd = open(cert_file, O_RDONLY)) == -1){
33 eef_log(LOG_ERR, "Cannot open file %s: %s\n", cert_file, strerror(errno));
34 }
35
36 if(fstat(_fd, &_stat) == -1){
37 eef_log(LOG_ERR, "Cannot stat file %s: %s\n", cert_file, strerror(errno));
38 return EES_PL_FAILURE;
39 }
40
41 if(!(_string = calloc(1, (_stat.st_size+1)*sizeof(char)))){
42 eef_log(LOG_ERR, "Out of memory!");
43 return EES_PL_FAILURE;
44 }
45
46
47 if((read(_fd, _string, _stat.st_size)) == -1){
48 eef_log(LOG_ERR, "Cannot read file %s\n", cert_file);
49 return EES_PL_FAILURE;
50 } else {
51 #ifdef HAVE_LONG_LONG_INT
52 printf("Read %lld bytes from file '%s'\n", (long long int) _stat.st_size, cert_file);
53 #else
54 printf("Read %ld bytes from file '%s'\n", (long int) _stat.st_size, cert_file);
55 #endif
56 /*setObligation("my_pemstring", _string);*/
57 /*pemstring = createAttribute();*/
58 /*setAttributeId(pemstring, "my_pemstring");*/
59 /*setAttributeValue(pemstring, _string, strlen(_string));*/
60
61 /*if((context = getNextContext(ANY, NULL)) == NULL){*/
62 /*context = createContext(ANY);*/
63 /*addContext(context);*/
64 /*}*/
65
66 /*addAttribute(context, pemstring);*/
67
68
69 return EES_PL_SUCCESS;
70 }
71
72 return EES_PL_FAILURE;
73 }
74
75 EES_PL_RC plugin_run(){
76 eef_log(LOG_ERR, "Getting 'pemstring'\n");
77
78 pemstring = createAttribute();
79 setAttributeId(pemstring, "my_pemstring");
80 setAttributeValue(pemstring, _string, strlen(_string));
81
82 if((_context = getNextContext(ANY, NULL)) == NULL){
83 _context = createContext(ANY);
84 addContext(_context);
85 }
86
87 addAttribute(_context, pemstring);
88
89 /*context = getNextContext(ANY,NULL);*/
90 /*while(pemstring = getNextAttribute(context)){*/
91 /*if(getAttributeId(pemstring) == "my_pemstring"){*/
92 /*eef_log(LOG_ERR, "my_pemstring: %s\n", getObligation("my_pemstring"));*/
93 /*}*/
94 /*}*/
95
96 eef_log(LOG_ERR, "Setting 'pemstring' leeg\n");
97 /*setObligation("my_pemstring", "Leeggehaald\n");*/
98 /*setObligation("foo", "barbaz");*/
99 return EES_PL_SUCCESS;
100 }
101
102 EES_PL_RC plugin_terminate(){
103 /*destroyObligation("my_pemstring");*/
104 free(cert_file);
105 if(_fd > 0){
106 close(_fd);
107 free(_string);
108 }
109 return EES_PL_SUCCESS;
110 }

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