Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixes EUCA-3962 where a string buffer may endup not null terminated.

Fixes Coverity issue #11096.
  • Loading branch information...
commit 2c03873b939b46a2dfca90b14ac5163b0399085e 1 parent e788d9e
gelinasc authored November 21, 2012
75  gatherlog/GLclient.c
@@ -65,39 +65,46 @@
65 65
 #include <gl-client-marshal.h>
66 66
 #include <euca_auth.h>
67 67
 
68  
-int main(int argc, char **argv) {
69  
-  axutil_env_t * env = NULL;
70  
-  axis2_char_t * client_home = NULL;
71  
-  axis2_char_t endpoint_uri[256], *tmpstr;
72  
-  axis2_stub_t * stub = NULL;
73  
-  int rc, i;
74  
-  char *euca_home;
75  
-  
76  
-  snprintf(endpoint_uri, 256," http://%s/axis2/services/EucalyptusGL", argv[1]);
77  
-  //  env =  axutil_env_create_all("/tmp/GLclient.log", AXIS2_LOG_LEVEL_TRACE);
78  
-  env =  axutil_env_create_all("/tmp/fooh", AXIS2_LOG_LEVEL_TRACE);
79  
-  client_home = AXIS2_GETENV("AXIS2C_HOME");
80  
-  if (!client_home) {
81  
-    printf("must have AXIS2C_HOME set\n");
82  
-  }
83  
-  stub = axis2_stub_create_EucalyptusGL(env, client_home, endpoint_uri);
  68
+int main(int argc, char **argv)
  69
+{
  70
+	axutil_env_t *env = NULL;
  71
+	axis2_char_t *client_home = NULL;
  72
+	axis2_char_t endpoint_uri[256], *tmpstr;
  73
+	axis2_stub_t *stub = NULL;
  74
+	int rc, i;
  75
+	char *euca_home;
84 76
 
85  
-  if (!strcmp(argv[2], "getLogs")) {
86  
-    char *clog, *nlog, *hlog, *alog;
87  
-    rc = gl_getLogs(argv[3], &clog, &nlog, &hlog, &alog, env, stub);
88  
-    if (!rc) {
89  
-      if (clog) printf("CLOG\n----------\n%s\n-----------\n", base64_dec((unsigned char *)clog, strlen(clog)));
90  
-      if (nlog) printf("NLOG\n----------\n%s\n-----------\n", base64_dec((unsigned char *)nlog, strlen(nlog)));
91  
-      if (hlog) printf("HLOG\n----------\n%s\n-----------\n", base64_dec((unsigned char *)hlog, strlen(hlog)));
92  
-      if (alog) printf("ALOG\n----------\n%s\n-----------\n", base64_dec((unsigned char *)alog, strlen(alog)));
93  
-    }
94  
-  } else if (!strcmp(argv[2], "getKeys")) {
95  
-    char *cccert, *nccert;
96  
-    rc = gl_getKeys(argv[3], &cccert, &nccert, env, stub);
97  
-    if (!rc) {
98  
-      if (cccert) printf("CCCERT\n----------\n%s\n-----------\n", base64_dec((unsigned char *)cccert, strlen(cccert)));
99  
-      if (nccert) printf("NCCERT\n----------\n%s\n-----------\n", base64_dec((unsigned char *)nccert, strlen(nccert)));
100  
-    }
101  
-  }
102  
-  exit(0);
  77
+	snprintf(endpoint_uri, 256, " http://%s/axis2/services/EucalyptusGL", argv[1]);
  78
+	//  env =  axutil_env_create_all("/tmp/GLclient.log", AXIS2_LOG_LEVEL_TRACE);
  79
+	env = axutil_env_create_all("/tmp/fooh", AXIS2_LOG_LEVEL_TRACE);
  80
+	client_home = AXIS2_GETENV("AXIS2C_HOME");
  81
+	if (!client_home) {
  82
+		printf("must have AXIS2C_HOME set\n");
  83
+	}
  84
+	stub = axis2_stub_create_EucalyptusGL(env, client_home, endpoint_uri);
  85
+
  86
+	if (!strcmp(argv[2], "getLogs")) {
  87
+		char *clog, *nlog, *hlog, *alog;
  88
+		rc = gl_getLogs(argv[3], &clog, &nlog, &hlog, &alog, env, stub);
  89
+		if (!rc) {
  90
+			if (clog)
  91
+				printf("CLOG\n----------\n%s\n-----------\n", base64_dec((unsigned char *)clog, strlen(clog)));
  92
+			if (nlog)
  93
+				printf("NLOG\n----------\n%s\n-----------\n", base64_dec((unsigned char *)nlog, strlen(nlog)));
  94
+			if (hlog)
  95
+				printf("HLOG\n----------\n%s\n-----------\n", base64_dec((unsigned char *)hlog, strlen(hlog)));
  96
+			if (alog)
  97
+				printf("ALOG\n----------\n%s\n-----------\n", base64_dec((unsigned char *)alog, strlen(alog)));
  98
+		}
  99
+	} else if (!strcmp(argv[2], "getKeys")) {
  100
+		char *cccert, *nccert;
  101
+		rc = gl_getKeys(argv[3], &cccert, &nccert, env, stub);
  102
+		if (!rc) {
  103
+			if (cccert)
  104
+				printf("CCCERT\n----------\n%s\n-----------\n", base64_dec((unsigned char *)cccert, strlen(cccert)));
  105
+			if (nccert)
  106
+				printf("NCCERT\n----------\n%s\n-----------\n", base64_dec((unsigned char *)nccert, strlen(nccert)));
  107
+		}
  108
+	}
  109
+	exit(0);
103 110
 }
4  gatherlog/Makefile
@@ -121,6 +121,10 @@ deploy:
121 121
 # no ws
122 122
 	$(INSTALL) $(DESTDIR)$(AXIS2C_SERVICES)/$(SERVICE_NAME)/services_noWS.xml $(DESTDIR)$(AXIS2C_SERVICES)/$(SERVICE_NAME)/services.xml
123 123
 
  124
+indent:
  125
+	@indent *.[ch] -nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -d0 -di1 -nfc1 -i4 -ut -ip0 -l200 -lp -npcs -nprs -npsl -sai -saf -saw -ncs -nsc -sob -nfca -ss -ts4 -il0 -nip
  126
+	@\rm *.*~
  127
+
124 128
 clean:
125 129
 	rm -f $(SERVICE_SO) *.o $(CLIENT) *~* *#*  
126 130
 
122  gatherlog/gl-client-marshal-adb.c
@@ -65,66 +65,68 @@
65 65
 #include <gl-client-marshal.h>
66 66
 #include <euca_auth.h>
67 67
 
68  
-int gl_getLogs(char *service, char **outCClog, char **outNClog, char **outHlog, char **outAlog, axutil_env_t *env, axis2_stub_t *stub) {
69  
-  char *outservice;
70  
-  
71  
-  adb_GetLogsResponse_t *out;
72  
-  adb_getLogsResponseType_t *response;
73  
-
74  
-  adb_GetLogs_t *in;
75  
-  adb_getLogsType_t *request;
76  
-
77  
-  request = adb_getLogsType_create(env);
78  
-  adb_getLogsType_set_userId(request, env, "eucalyptus");
79  
-  adb_getLogsType_set_correlationId(request, env, "12345678");
80  
-  adb_getLogsType_set_serviceTag(request, env, service);
81  
-
82  
-  in = adb_GetLogs_create(env);
83  
-  adb_GetLogs_set_GetLogs(in, env, request);
84  
-
85  
-  out =  axis2_stub_op_EucalyptusGL_GetLogs(stub, env, in);
86  
-  if (!out) {
87  
-    printf("ERROR: operation call failed\n");
88  
-    return(1);
89  
-  }
90  
-  response = adb_GetLogsResponse_get_GetLogsResponse(out, env);
91  
-
92  
-  //outservice = adb_getLogsResponseType_get_serviceTag(response, env);
93  
-  *outCClog = adb_getLogsResponseType_get_CCLog(response, env);
94  
-  *outNClog = adb_getLogsResponseType_get_NCLog(response, env);
95  
-  *outHlog = adb_getLogsResponseType_get_httpdLog(response, env);
96  
-  *outAlog = adb_getLogsResponseType_get_axis2Log(response, env);
97  
-
98  
-  return(0);
  68
+int gl_getLogs(char *service, char **outCClog, char **outNClog, char **outHlog, char **outAlog, axutil_env_t * env, axis2_stub_t * stub)
  69
+{
  70
+	char *outservice;
  71
+
  72
+	adb_GetLogsResponse_t *out;
  73
+	adb_getLogsResponseType_t *response;
  74
+
  75
+	adb_GetLogs_t *in;
  76
+	adb_getLogsType_t *request;
  77
+
  78
+	request = adb_getLogsType_create(env);
  79
+	adb_getLogsType_set_userId(request, env, "eucalyptus");
  80
+	adb_getLogsType_set_correlationId(request, env, "12345678");
  81
+	adb_getLogsType_set_serviceTag(request, env, service);
  82
+
  83
+	in = adb_GetLogs_create(env);
  84
+	adb_GetLogs_set_GetLogs(in, env, request);
  85
+
  86
+	out = axis2_stub_op_EucalyptusGL_GetLogs(stub, env, in);
  87
+	if (!out) {
  88
+		printf("ERROR: operation call failed\n");
  89
+		return (1);
  90
+	}
  91
+	response = adb_GetLogsResponse_get_GetLogsResponse(out, env);
  92
+
  93
+	//outservice = adb_getLogsResponseType_get_serviceTag(response, env);
  94
+	*outCClog = adb_getLogsResponseType_get_CCLog(response, env);
  95
+	*outNClog = adb_getLogsResponseType_get_NCLog(response, env);
  96
+	*outHlog = adb_getLogsResponseType_get_httpdLog(response, env);
  97
+	*outAlog = adb_getLogsResponseType_get_axis2Log(response, env);
  98
+
  99
+	return (0);
99 100
 }
100 101
 
101  
-int gl_getKeys(char *service, char **outCCCert, char **outNCCert, axutil_env_t *env, axis2_stub_t *stub) {
102  
-  char *outservice;
103  
-  
104  
-  adb_GetKeysResponse_t *out;
105  
-  adb_getKeysResponseType_t *response;
106  
-  
107  
-  adb_GetKeys_t *in;
108  
-  adb_getKeysType_t *request;
109  
-  
110  
-  request = adb_getKeysType_create(env);
111  
-  adb_getKeysType_set_userId(request, env, "eucalyptus");
112  
-  adb_getKeysType_set_correlationId(request, env, "12345678");
113  
-  adb_getKeysType_set_serviceTag(request, env, service);
114  
-  
115  
-  in = adb_GetKeys_create(env);
116  
-  adb_GetKeys_set_GetKeys(in, env, request);
117  
-  
118  
-  out =  axis2_stub_op_EucalyptusGL_GetKeys(stub, env, in);
119  
-  if (!out) {
120  
-    printf("ERROR: operation call failed\n");
121  
-    return(1);
122  
-  }
123  
-  response = adb_GetKeysResponse_get_GetKeysResponse(out, env);
124  
-  
125  
-  //outservice = adb_getKeysResponseType_get_serviceTag(response, env);
126  
-  *outCCCert = adb_getKeysResponseType_get_CCcert(response, env);
127  
-  *outNCCert = adb_getKeysResponseType_get_NCcert(response, env);
128  
-
129  
-  return(0);
  102
+int gl_getKeys(char *service, char **outCCCert, char **outNCCert, axutil_env_t * env, axis2_stub_t * stub)
  103
+{
  104
+	char *outservice;
  105
+
  106
+	adb_GetKeysResponse_t *out;
  107
+	adb_getKeysResponseType_t *response;
  108
+
  109
+	adb_GetKeys_t *in;
  110
+	adb_getKeysType_t *request;
  111
+
  112
+	request = adb_getKeysType_create(env);
  113
+	adb_getKeysType_set_userId(request, env, "eucalyptus");
  114
+	adb_getKeysType_set_correlationId(request, env, "12345678");
  115
+	adb_getKeysType_set_serviceTag(request, env, service);
  116
+
  117
+	in = adb_GetKeys_create(env);
  118
+	adb_GetKeys_set_GetKeys(in, env, request);
  119
+
  120
+	out = axis2_stub_op_EucalyptusGL_GetKeys(stub, env, in);
  121
+	if (!out) {
  122
+		printf("ERROR: operation call failed\n");
  123
+		return (1);
  124
+	}
  125
+	response = adb_GetKeysResponse_get_GetKeysResponse(out, env);
  126
+
  127
+	//outservice = adb_getKeysResponseType_get_serviceTag(response, env);
  128
+	*outCCCert = adb_getKeysResponseType_get_CCcert(response, env);
  129
+	*outNCCert = adb_getKeysResponseType_get_NCcert(response, env);
  130
+
  131
+	return (0);
130 132
 }
4  gatherlog/gl-client-marshal.h
@@ -67,8 +67,8 @@
67 67
 #include <time.h>
68 68
 #include "axis2_stub_EucalyptusGL.h"
69 69
 
70  
-int gl_getLogs(char *service, char **outCClog, char **outNClog, char **outHlog, char **outAlog, axutil_env_t *env, axis2_stub_t *stub);
  70
+int gl_getLogs(char *service, char **outCClog, char **outNClog, char **outHlog, char **outAlog, axutil_env_t * env, axis2_stub_t * stub);
71 71
 
72  
-int gl_getKeys(char *service, char **outCCCert, char **outNCCert, axutil_env_t *env, axis2_stub_t *stub);
  72
+int gl_getKeys(char *service, char **outCCCert, char **outNCCert, axutil_env_t * env, axis2_stub_t * stub);
73 73
 
74 74
 #endif
579  gatherlog/handlers.c
@@ -76,292 +76,307 @@
76 76
 
77 77
 #include <eucalyptus.h>
78 78
 
79  
-int doGetLogs(char *service, char **outCCLog, char **outNCLog, char **outHTTPDLog, char **outAxis2Log) {
80  
-  char *home, file[MAX_PATH], *buf;
81  
-  int fd, rc, bufsize;
82  
-  
83  
-  *outCCLog = *outNCLog = *outHTTPDLog = *outAxis2Log = NULL;
84  
-  if (!service) return(1);
85  
-  
86  
-  bufsize = 1000 * 1024;
87  
-  buf = malloc(bufsize);
88  
-  if (!buf) {
89  
-      printf("Out of memory!\n");
90  
-      return 1;
91  
-  }
92  
-  
93  
-  if (!strcmp(service, "self")) {
94  
-    char *tmp;
95  
-    home = NULL;
96  
-    tmp = getenv("EUCALYPTUS");
97  
-    if (tmp) home = strdup(tmp);
98  
-    if (!home) {
99  
-       home = strdup("");
100  
-    }
101  
-    if (!home) {
102  
-      printf("Out of memory!\n");
103  
-      free(buf);
104  
-      return 1;
105  
-    }
106  
-
107  
-    
108  
-    snprintf(file, MAX_PATH, EUCALYPTUS_LOG_DIR "/cc.log", home);
109  
-    fd = open(file, O_RDONLY);
110  
-    if (fd >= 0) {
111  
-      bzero(buf, bufsize);
112  
-      lseek(fd, -1 * bufsize, SEEK_END);
113  
-      rc = read(fd, buf, bufsize);
114  
-      if (rc > 0) {
115  
-	*outCCLog = base64_enc((unsigned char *)buf, strlen(buf));
116  
-      }
117  
-      close(fd);
118  
-    } else {
119  
-      *outCCLog = NULL;
120  
-    }
121  
-    
122  
-    snprintf(file, MAX_PATH, EUCALYPTUS_LOG_DIR "/nc.log", home);
123  
-    fd = open(file, O_RDONLY);
124  
-    if (fd >= 0) {
125  
-      bzero(buf, bufsize);
126  
-      lseek(fd, -1 * bufsize, SEEK_END);
127  
-      rc = read(fd, buf, bufsize);
128  
-      if (rc > 0) {
129  
-	*outNCLog = base64_enc((unsigned char *)buf, strlen(buf));
130  
-      }
131  
-      close(fd);
132  
-    } else {
133  
-      *outNCLog = NULL;
134  
-    }
135  
-    
136  
-    bzero(buf, bufsize);
137  
-    snprintf(file, MAX_PATH, EUCALYPTUS_LOG_DIR "/httpd-nc_error_log", home);
138  
-    fd = open(file, O_RDONLY);
139  
-    if (fd < 0) {
140  
-      snprintf(file, MAX_PATH, EUCALYPTUS_LOG_DIR "/httpd-cc_error_log", home);
141  
-      fd = open(file, O_RDONLY);
142  
-    }
143  
-    if (fd >= 0) {
144  
-      bzero(buf, bufsize);
145  
-      rc = read(fd, buf, bufsize);
146  
-      if (rc > 0) {
147  
-	*outHTTPDLog = base64_enc((unsigned char *)buf, strlen(buf));
148  
-      }
149  
-      close(fd);
150  
-    } else {
151  
-      *outHTTPDLog = NULL;
152  
-    }
153  
-    
154  
-    bzero(buf, bufsize);
155  
-    snprintf(file, MAX_PATH, EUCALYPTUS_LOG_DIR "/axis2c.log", home);
156  
-    fd = open(file, O_RDONLY);
157  
-    if (fd >= 0) {
158  
-      bzero(buf, bufsize);
159  
-      rc = read(fd, buf, bufsize);
160  
-      if (rc > 0) {
161  
-	*outAxis2Log = base64_enc((unsigned char *)buf, strlen(buf));
162  
-      }
163  
-      close(fd);
164  
-    } else {
165  
-      *outAxis2Log = NULL;
166  
-    }
167  
-    if (home) free(home);
168  
-  } else {
169  
-    int pid, filedes[2], status;
170  
-    
171  
-    pipe(filedes);
172  
-    pid = fork();
173  
-    if (pid == 0) {
174  
-      axutil_env_t * env = NULL;
175  
-      axis2_char_t * client_home = NULL;
176  
-      axis2_char_t endpoint_uri[256], *tmpstr;
177  
-      axis2_stub_t * stub = NULL;
178  
-      char *clog, *hlog, *alog, *nlog;
179  
-      
180  
-      close(filedes[0]);
181  
-      
182  
-      //      env =  axutil_env_create_all("/tmp/GLclient.log", AXIS2_LOG_LEVEL_TRACE);
183  
-      env =  axutil_env_create_all(NULL, 0);
184  
-      client_home = AXIS2_GETENV("AXIS2C_HOME");
185  
-      if (!client_home) {
186  
-	exit(1);
187  
-      } else {
188  
-	stub = axis2_stub_create_EucalyptusGL(env, client_home, service);
189  
-	clog = nlog = hlog = alog = NULL;
190  
-	rc = gl_getLogs("self", &clog, &nlog, &hlog, &alog, env, stub);
191  
-	if (rc) {
  79
+int doGetLogs(char *service, char **outCCLog, char **outNCLog, char **outHTTPDLog, char **outAxis2Log)
  80
+{
  81
+	char *home, file[MAX_PATH], *buf;
  82
+	int fd, rc, bufsize;
  83
+
  84
+	*outCCLog = *outNCLog = *outHTTPDLog = *outAxis2Log = NULL;
  85
+	if (!service)
  86
+		return (1);
  87
+
  88
+	bufsize = 1000 * 1024;
  89
+	buf = malloc(bufsize);
  90
+	if (!buf) {
  91
+		printf("Out of memory!\n");
  92
+		return 1;
  93
+	}
  94
+
  95
+	if (!strcmp(service, "self")) {
  96
+		char *tmp;
  97
+		home = NULL;
  98
+		tmp = getenv("EUCALYPTUS");
  99
+		if (tmp)
  100
+			home = strdup(tmp);
  101
+		if (!home) {
  102
+			home = strdup("");
  103
+		}
  104
+		if (!home) {
  105
+			printf("Out of memory!\n");
  106
+			free(buf);
  107
+			return 1;
  108
+		}
  109
+
  110
+		snprintf(file, MAX_PATH, EUCALYPTUS_LOG_DIR "/cc.log", home);
  111
+		fd = open(file, O_RDONLY);
  112
+		if (fd >= 0) {
  113
+			bzero(buf, bufsize);
  114
+			lseek(fd, -1 * bufsize, SEEK_END);
  115
+			rc = read(fd, buf, bufsize);
  116
+			if (rc > 0) {
  117
+				*outCCLog = base64_enc((unsigned char *)buf, strlen(buf));
  118
+			}
  119
+			close(fd);
  120
+		} else {
  121
+			*outCCLog = NULL;
  122
+		}
  123
+
  124
+		snprintf(file, MAX_PATH, EUCALYPTUS_LOG_DIR "/nc.log", home);
  125
+		fd = open(file, O_RDONLY);
  126
+		if (fd >= 0) {
  127
+			bzero(buf, bufsize);
  128
+			lseek(fd, -1 * bufsize, SEEK_END);
  129
+			rc = read(fd, buf, bufsize);
  130
+			if (rc > 0) {
  131
+				*outNCLog = base64_enc((unsigned char *)buf, strlen(buf));
  132
+			}
  133
+			close(fd);
  134
+		} else {
  135
+			*outNCLog = NULL;
  136
+		}
  137
+
  138
+		bzero(buf, bufsize);
  139
+		snprintf(file, MAX_PATH, EUCALYPTUS_LOG_DIR "/httpd-nc_error_log", home);
  140
+		fd = open(file, O_RDONLY);
  141
+		if (fd < 0) {
  142
+			snprintf(file, MAX_PATH, EUCALYPTUS_LOG_DIR "/httpd-cc_error_log", home);
  143
+			fd = open(file, O_RDONLY);
  144
+		}
  145
+		if (fd >= 0) {
  146
+			bzero(buf, bufsize);
  147
+			rc = read(fd, buf, bufsize);
  148
+			if (rc > 0) {
  149
+				*outHTTPDLog = base64_enc((unsigned char *)buf, strlen(buf));
  150
+			}
  151
+			close(fd);
  152
+		} else {
  153
+			*outHTTPDLog = NULL;
  154
+		}
  155
+
  156
+		bzero(buf, bufsize);
  157
+		snprintf(file, MAX_PATH, EUCALYPTUS_LOG_DIR "/axis2c.log", home);
  158
+		fd = open(file, O_RDONLY);
  159
+		if (fd >= 0) {
  160
+			bzero(buf, bufsize);
  161
+			rc = read(fd, buf, bufsize);
  162
+			if (rc > 0) {
  163
+				*outAxis2Log = base64_enc((unsigned char *)buf, strlen(buf));
  164
+			}
  165
+			close(fd);
  166
+		} else {
  167
+			*outAxis2Log = NULL;
  168
+		}
  169
+		if (home)
  170
+			free(home);
192 171
 	} else {
193  
-	  bzero(buf, bufsize);
194  
-	  if (clog) snprintf(buf, bufsize, "%s", clog);
195  
-	  rc = write(filedes[1], buf, bufsize);
196  
-
197  
-	  bzero(buf, bufsize);
198  
-	  if (nlog) snprintf(buf, bufsize, "%s", nlog);
199  
-	  rc = write(filedes[1], buf, bufsize);
200  
-	  
201  
-	  bzero(buf, bufsize);
202  
-	  if (hlog) snprintf(buf, bufsize, "%s", hlog);
203  
-	  rc = write(filedes[1], buf, bufsize);
204  
-	  
205  
-	  bzero(buf, bufsize);
206  
-	  if (alog) snprintf(buf, bufsize, "%s", alog);
207  
-	  rc = write(filedes[1], buf, bufsize);
  172
+		int pid, filedes[2], status;
  173
+
  174
+		pipe(filedes);
  175
+		pid = fork();
  176
+		if (pid == 0) {
  177
+			axutil_env_t *env = NULL;
  178
+			axis2_char_t *client_home = NULL;
  179
+			axis2_char_t endpoint_uri[256], *tmpstr;
  180
+			axis2_stub_t *stub = NULL;
  181
+			char *clog, *hlog, *alog, *nlog;
  182
+
  183
+			close(filedes[0]);
  184
+
  185
+			//      env =  axutil_env_create_all("/tmp/GLclient.log", AXIS2_LOG_LEVEL_TRACE);
  186
+			env = axutil_env_create_all(NULL, 0);
  187
+			client_home = AXIS2_GETENV("AXIS2C_HOME");
  188
+			if (!client_home) {
  189
+				exit(1);
  190
+			} else {
  191
+				stub = axis2_stub_create_EucalyptusGL(env, client_home, service);
  192
+				clog = nlog = hlog = alog = NULL;
  193
+				rc = gl_getLogs("self", &clog, &nlog, &hlog, &alog, env, stub);
  194
+				if (rc) {
  195
+				} else {
  196
+					bzero(buf, bufsize);
  197
+					if (clog)
  198
+						snprintf(buf, bufsize, "%s", clog);
  199
+					rc = write(filedes[1], buf, bufsize);
  200
+
  201
+					bzero(buf, bufsize);
  202
+					if (nlog)
  203
+						snprintf(buf, bufsize, "%s", nlog);
  204
+					rc = write(filedes[1], buf, bufsize);
  205
+
  206
+					bzero(buf, bufsize);
  207
+					if (hlog)
  208
+						snprintf(buf, bufsize, "%s", hlog);
  209
+					rc = write(filedes[1], buf, bufsize);
  210
+
  211
+					bzero(buf, bufsize);
  212
+					if (alog)
  213
+						snprintf(buf, bufsize, "%s", alog);
  214
+					rc = write(filedes[1], buf, bufsize);
  215
+				}
  216
+			}
  217
+			close(filedes[1]);
  218
+			exit(0);
  219
+
  220
+		} else {
  221
+			close(filedes[1]);
  222
+
  223
+			bzero(buf, bufsize);
  224
+			rc = read(filedes[0], buf, bufsize - 1);
  225
+			if (rc && buf[0] != '\0') {
  226
+				*outCCLog = strdup(buf);
  227
+			}
  228
+
  229
+			bzero(buf, bufsize);
  230
+			rc = read(filedes[0], buf, bufsize - 1);
  231
+			if (rc && buf[0] != '\0') {
  232
+				*outNCLog = strdup(buf);
  233
+			}
  234
+
  235
+			bzero(buf, bufsize);
  236
+			rc = read(filedes[0], buf, bufsize - 1);
  237
+			if (rc && buf[0] != '\0') {
  238
+				*outHTTPDLog = strdup(buf);
  239
+			}
  240
+
  241
+			bzero(buf, bufsize);
  242
+			rc = read(filedes[0], buf, bufsize - 1);
  243
+			if (rc && buf[0] != '\0') {
  244
+				*outAxis2Log = strdup(buf);
  245
+			}
  246
+			close(filedes[0]);
  247
+			wait(&status);
  248
+		}
208 249
 	}
209  
-      }
210  
-      close(filedes[1]);
211  
-      exit(0);
212  
-
213  
-    } else {
214  
-      close(filedes[1]);
215  
-
216  
-      bzero(buf, bufsize);
217  
-      rc = read(filedes[0], buf, bufsize - 1);
218  
-      if (rc && buf[0] != '\0') {
219  
-	*outCCLog = strdup(buf);
220  
-      }
221  
-
222  
-      bzero(buf, bufsize);
223  
-      rc = read(filedes[0], buf, bufsize - 1);
224  
-      if (rc && buf[0] != '\0') {
225  
-	*outNCLog = strdup(buf);
226  
-      }
227  
-
228  
-      bzero(buf, bufsize);
229  
-      rc = read(filedes[0], buf, bufsize - 1);
230  
-      if (rc && buf[0] != '\0') {
231  
-	*outHTTPDLog = strdup(buf);
232  
-      }
233  
-
234  
-      bzero(buf, bufsize);
235  
-      rc = read(filedes[0], buf, bufsize - 1);
236  
-      if (rc && buf[0] != '\0') {
237  
-	*outAxis2Log = strdup(buf);
238  
-      }
239  
-      close(filedes[0]);
240  
-      wait(&status);
241  
-    }
242  
-  }
243  
-  
244  
-  if (buf) free(buf);
245  
-  
246  
-  return(0);
  250
+
  251
+	if (buf)
  252
+		free(buf);
  253
+
  254
+	return (0);
247 255
 }
248 256
 
249  
-int doGetKeys(char *service, char **outCCCert, char **outNCCert) {
250  
-  char *home, file[MAX_PATH], *buf;
251  
-  int fd, rc, bufsize;
252  
-
253  
-  *outCCCert = *outNCCert = NULL;
254  
-  if (!service) return(1);
255  
- 
256  
-  
257  
-  bufsize = 1000 * 1024;
258  
-  buf = malloc(bufsize);
259  
-  if (!buf) {
260  
-     printf("Out of memory!\n");
261  
-     return 1;
262  
-  }
263  
-  
264  
-  if (!strcmp(service, "self")) {
265  
-    char *tmp;
266  
-    home = NULL;
267  
-    tmp = getenv("EUCALYPTUS");
268  
-    if (tmp) home = strdup(tmp);
269  
-    if (!home) {
270  
-      home = strdup("");
271  
-    }
272  
-    if (!home) {
273  
-      printf("Out of memory!\n");
274  
-      free(buf);
275  
-      return 1;
276  
-    }
277  
-    
278  
-    snprintf(file, MAX_PATH, EUCALYPTUS_KEYS_DIR "/cluster-cert.pem", home);
279  
-    fd = open(file, O_RDONLY);
280  
-    if (fd >= 0) {
281  
-      bzero(buf, bufsize);
282  
-      lseek(fd, -1 * bufsize, SEEK_END);
283  
-      rc = read(fd, buf, bufsize);
284  
-      if (rc > 0) {
285  
-	*outCCCert = base64_enc((unsigned char *)buf, strlen(buf));
286  
-      }
287  
-      close(fd);
288  
-    } else {
289  
-      *outCCCert = NULL;
290  
-    }
291  
-    
292  
-    bzero(buf, bufsize);
293  
-    snprintf(file, MAX_PATH, EUCALYPTUS_KEYS_DIR "/node-cert.pem", home);
294  
-    fd = open(file, O_RDONLY);
295  
-    if (fd >= 0) {
296  
-      bzero(buf, bufsize);
297  
-      lseek(fd, -1 * bufsize, SEEK_END);
298  
-      // make sure that buf is NULL terminated
299  
-      rc = read(fd, buf, bufsize - 1);
300  
-      if (rc > 0) {
301  
-	*outNCCert = base64_enc((unsigned char *)buf, strlen(buf));
302  
-      }
303  
-      close(fd);
304  
-    } else {
305  
-      *outNCCert = NULL;
306  
-    }
307  
-    
308  
-    if (home) free(home);
309  
-  } else {
310  
-    int pid, filedes[2], status;
311  
-    
312  
-    pipe(filedes);
313  
-    pid = fork();
314  
-    if (pid == 0) {
315  
-      axutil_env_t * env = NULL;
316  
-      axis2_char_t * client_home = NULL;
317  
-      axis2_char_t endpoint_uri[256], *tmpstr;
318  
-      axis2_stub_t * stub = NULL;
319  
-      char *ccert, *ncert;
320  
-      
321  
-      close(filedes[0]);
322  
-      
323  
-      //      env =  axutil_env_create_all("/tmp/GLclient.log", AXIS2_LOG_LEVEL_TRACE);
324  
-      env =  axutil_env_create_all(NULL, 0);
325  
-      client_home = AXIS2_GETENV("AXIS2C_HOME");
326  
-      if (!client_home) {
327  
-	exit(1);
328  
-      } else {
329  
-	stub = axis2_stub_create_EucalyptusGL(env, client_home, service);
330  
-	ccert = ncert = NULL;
331  
-	rc = gl_getKeys("self", &ccert, &ncert, env, stub);
332  
-	if (rc) {
  257
+int doGetKeys(char *service, char **outCCCert, char **outNCCert)
  258
+{
  259
+	char *home, file[MAX_PATH], *buf;
  260
+	int fd, rc, bufsize;
  261
+
  262
+	*outCCCert = *outNCCert = NULL;
  263
+	if (!service)
  264
+		return (1);
  265
+
  266
+	bufsize = 1000 * 1024;
  267
+	buf = malloc(bufsize);
  268
+	if (!buf) {
  269
+		printf("Out of memory!\n");
  270
+		return 1;
  271
+	}
  272
+
  273
+	if (!strcmp(service, "self")) {
  274
+		char *tmp;
  275
+		home = NULL;
  276
+		tmp = getenv("EUCALYPTUS");
  277
+		if (tmp)
  278
+			home = strdup(tmp);
  279
+		if (!home) {
  280
+			home = strdup("");
  281
+		}
  282
+		if (!home) {
  283
+			printf("Out of memory!\n");
  284
+			free(buf);
  285
+			return 1;
  286
+		}
  287
+
  288
+		snprintf(file, MAX_PATH, EUCALYPTUS_KEYS_DIR "/cluster-cert.pem", home);
  289
+		fd = open(file, O_RDONLY);
  290
+		if (fd >= 0) {
  291
+			bzero(buf, bufsize);
  292
+			lseek(fd, -1 * bufsize, SEEK_END);
  293
+			rc = read(fd, buf, bufsize - 1);
  294
+			if (rc > 0) {
  295
+				*outCCCert = base64_enc((unsigned char *)buf, strlen(buf));
  296
+			}
  297
+			close(fd);
  298
+		} else {
  299
+			*outCCCert = NULL;
  300
+		}
  301
+
  302
+		bzero(buf, bufsize);
  303
+		snprintf(file, MAX_PATH, EUCALYPTUS_KEYS_DIR "/node-cert.pem", home);
  304
+		fd = open(file, O_RDONLY);
  305
+		if (fd >= 0) {
  306
+			bzero(buf, bufsize);
  307
+			lseek(fd, -1 * bufsize, SEEK_END);
  308
+			// make sure that buf is NULL terminated
  309
+			rc = read(fd, buf, bufsize - 1);
  310
+			if (rc > 0) {
  311
+				*outNCCert = base64_enc((unsigned char *)buf, strlen(buf));
  312
+			}
  313
+			close(fd);
  314
+		} else {
  315
+			*outNCCert = NULL;
  316
+		}
  317
+
  318
+		if (home)
  319
+			free(home);
333 320
 	} else {
334  
-	  bzero(buf, bufsize);
335  
-	  if (ccert) snprintf(buf, bufsize, "%s", ccert);
336  
-	  rc = write(filedes[1], buf, bufsize);
337  
-	  
338  
-	  bzero(buf, bufsize);
339  
-	  if (ncert) snprintf(buf, bufsize, "%s", ncert);
340  
-	  rc = write(filedes[1], buf, bufsize);
  321
+		int pid, filedes[2], status;
  322
+
  323
+		pipe(filedes);
  324
+		pid = fork();
  325
+		if (pid == 0) {
  326
+			axutil_env_t *env = NULL;
  327
+			axis2_char_t *client_home = NULL;
  328
+			axis2_char_t endpoint_uri[256], *tmpstr;
  329
+			axis2_stub_t *stub = NULL;
  330
+			char *ccert, *ncert;
  331
+
  332
+			close(filedes[0]);
  333
+
  334
+			//      env =  axutil_env_create_all("/tmp/GLclient.log", AXIS2_LOG_LEVEL_TRACE);
  335
+			env = axutil_env_create_all(NULL, 0);
  336
+			client_home = AXIS2_GETENV("AXIS2C_HOME");
  337
+			if (!client_home) {
  338
+				exit(1);
  339
+			} else {
  340
+				stub = axis2_stub_create_EucalyptusGL(env, client_home, service);
  341
+				ccert = ncert = NULL;
  342
+				rc = gl_getKeys("self", &ccert, &ncert, env, stub);
  343
+				if (rc) {
  344
+				} else {
  345
+					bzero(buf, bufsize);
  346
+					if (ccert)
  347
+						snprintf(buf, bufsize, "%s", ccert);
  348
+					rc = write(filedes[1], buf, bufsize);
  349
+
  350
+					bzero(buf, bufsize);
  351
+					if (ncert)
  352
+						snprintf(buf, bufsize, "%s", ncert);
  353
+					rc = write(filedes[1], buf, bufsize);
  354
+				}
  355
+			}
  356
+			close(filedes[1]);
  357
+			exit(0);
  358
+
  359
+		} else {
  360
+			close(filedes[1]);
  361
+			bzero(buf, bufsize);
  362
+
  363
+			rc = read(filedes[0], buf, bufsize - 1);
  364
+			if (rc) {
  365
+				*outCCCert = strdup(buf);
  366
+			}
  367
+
  368
+			rc = read(filedes[0], buf, bufsize - 1);
  369
+			if (rc) {
  370
+				*outNCCert = strdup(buf);
  371
+			}
  372
+
  373
+			close(filedes[0]);
  374
+			wait(&status);
  375
+		}
341 376
 	}
342  
-      }
343  
-      close(filedes[1]);
344  
-      exit(0);
345  
-      
346  
-    } else {
347  
-      close(filedes[1]);
348  
-      
349  
-      rc = read(filedes[0], buf, bufsize);
350  
-      if (rc) {
351  
-	*outCCCert = strdup(buf);
352  
-      }
353  
-      
354  
-      rc = read(filedes[0], buf, bufsize);
355  
-      if (rc) {
356  
-	*outNCCert = strdup(buf);
357  
-      }
358  
-      
359  
-      close(filedes[0]);
360  
-      wait(&status);
361  
-    }
362  
-  }
363  
-  
364  
-  if (buf) free(buf);
365  
-  
366  
-  return(0);
  377
+
  378
+	if (buf)
  379
+		free(buf);
  380
+
  381
+	return (0);
367 382
 }
192  gatherlog/server-marshal.c
@@ -66,92 +66,112 @@
66 66
 
67 67
 #include <server-marshal.h>
68 68
 
69  
-adb_GetLogsResponse_t *GetLogsMarshal(adb_GetLogs_t *getLogs, const axutil_env_t *env) {
70  
-  adb_GetLogsResponse_t *ret=NULL;
71  
-  adb_getLogsResponseType_t *response=NULL;
72  
-  
73  
-  adb_getLogsType_t *request=NULL;
74  
-
75  
-  int rc;
76  
-  axis2_bool_t status;
77  
-  char *userId, *correlationId, *service, statusMessage[256];
78  
-  char *outCCLog, *outNCLog, *outHTTPDLog, *outAxis2Log;
79  
-
80  
-  request = adb_GetLogs_get_GetLogs(getLogs, env);
81  
-  
82  
-  userId = adb_getLogsType_get_userId(request, env);
83  
-  correlationId = adb_getLogsType_get_correlationId(request, env);
84  
-  service = adb_getLogsType_get_serviceTag(request, env);
85  
-  
86  
-  response = adb_getLogsResponseType_create(env);
87  
-
88  
-  status = AXIS2_TRUE;
89  
-  rc = doGetLogs(service, &outCCLog, &outNCLog, &outHTTPDLog, &outAxis2Log);
90  
-  if (rc) {
91  
-    status = AXIS2_FALSE;
92  
-    snprintf(statusMessage, 255, "ERROR");
93  
-  } else {
94  
-    
95  
-    if (outCCLog) {adb_getLogsResponseType_set_CCLog(response, env, outCCLog);free(outCCLog);}
96  
-    if (outNCLog) {adb_getLogsResponseType_set_NCLog(response, env, outNCLog);free(outNCLog);}
97  
-    if (outHTTPDLog) {adb_getLogsResponseType_set_httpdLog(response, env, outHTTPDLog);free(outHTTPDLog);}
98  
-    if (outAxis2Log) {adb_getLogsResponseType_set_axis2Log(response, env, outAxis2Log);free(outAxis2Log);}
99  
-  }
100  
-  adb_getLogsResponseType_set_serviceTag(response, env, service);
101  
-
102  
-  adb_getLogsResponseType_set_userId(response, env, userId);
103  
-  adb_getLogsResponseType_set_correlationId(response, env, correlationId);
104  
-  adb_getLogsResponseType_set_return(response, env, status);
105  
-  if (status == AXIS2_FALSE) {
106  
-    adb_getLogsResponseType_set_statusMessage(response, env, statusMessage);
107  
-  }
108  
-
109  
-  ret = adb_GetLogsResponse_create(env);
110  
-  adb_GetLogsResponse_set_GetLogsResponse(ret, env, response);
111  
-
112  
-  return(ret);
  69
+adb_GetLogsResponse_t *GetLogsMarshal(adb_GetLogs_t * getLogs, const axutil_env_t * env)
  70
+{
  71
+	adb_GetLogsResponse_t *ret = NULL;
  72
+	adb_getLogsResponseType_t *response = NULL;
  73
+
  74
+	adb_getLogsType_t *request = NULL;
  75
+
  76
+	int rc;
  77
+	axis2_bool_t status;
  78
+	char *userId, *correlationId, *service, statusMessage[256];
  79
+	char *outCCLog, *outNCLog, *outHTTPDLog, *outAxis2Log;
  80
+
  81
+	request = adb_GetLogs_get_GetLogs(getLogs, env);
  82
+
  83
+	userId = adb_getLogsType_get_userId(request, env);
  84
+	correlationId = adb_getLogsType_get_correlationId(request, env);
  85
+	service = adb_getLogsType_get_serviceTag(request, env);
  86
+
  87
+	response = adb_getLogsResponseType_create(env);
  88
+
  89
+	status = AXIS2_TRUE;
  90
+	rc = doGetLogs(service, &outCCLog, &outNCLog, &outHTTPDLog, &outAxis2Log);
  91
+	if (rc) {
  92
+		status = AXIS2_FALSE;
  93
+		snprintf(statusMessage, 255, "ERROR");
  94
+	} else {
  95
+
  96
+		if (outCCLog) {
  97
+			adb_getLogsResponseType_set_CCLog(response, env, outCCLog);
  98
+			free(outCCLog);
  99
+		}
  100
+		if (outNCLog) {
  101
+			adb_getLogsResponseType_set_NCLog(response, env, outNCLog);
  102
+			free(outNCLog);
  103
+		}
  104
+		if (outHTTPDLog) {
  105
+			adb_getLogsResponseType_set_httpdLog(response, env, outHTTPDLog);
  106
+			free(outHTTPDLog);
  107
+		}
  108
+		if (outAxis2Log) {
  109
+			adb_getLogsResponseType_set_axis2Log(response, env, outAxis2Log);
  110
+			free(outAxis2Log);
  111
+		}
  112
+	}
  113
+	adb_getLogsResponseType_set_serviceTag(response, env, service);
  114
+
  115
+	adb_getLogsResponseType_set_userId(response, env, userId);
  116
+	adb_getLogsResponseType_set_correlationId(response, env, correlationId);
  117
+	adb_getLogsResponseType_set_return(response, env, status);
  118
+	if (status == AXIS2_FALSE) {
  119
+		adb_getLogsResponseType_set_statusMessage(response, env, statusMessage);
  120
+	}
  121
+
  122
+	ret = adb_GetLogsResponse_create(env);
  123
+	adb_GetLogsResponse_set_GetLogsResponse(ret, env, response);
  124
+
  125
+	return (ret);
113 126
 }
114 127
 
115  
-adb_GetKeysResponse_t *GetKeysMarshal(adb_GetKeys_t *getKeys, const axutil_env_t *env) {
116  
-  adb_GetKeysResponse_t *ret=NULL;
117  
-  adb_getKeysResponseType_t *response=NULL;
118  
-  
119  
-  adb_getKeysType_t *request=NULL;
120  
-
121  
-  int rc;
122  
-  axis2_bool_t status;
123  
-  char *userId, *correlationId, *service, statusMessage[256];
124  
-  char *outCCCert, *outNCCert;
125  
-  
126  
-  request = adb_GetKeys_get_GetKeys(getKeys, env);
127  
-  
128  
-  userId = adb_getKeysType_get_userId(request, env);
129  
-  correlationId = adb_getKeysType_get_correlationId(request, env);
130  
-  service = adb_getKeysType_get_serviceTag(request, env);
131  
-  
132  
-  response = adb_getKeysResponseType_create(env);
133  
-
134  
-  status = AXIS2_TRUE;
135  
-  rc = doGetKeys(service, &outCCCert, &outNCCert);
136  
-  if (rc) {
137  
-    status = AXIS2_FALSE;
138  
-    snprintf(statusMessage, 255, "ERROR");
139  
-  } else {
140  
-    if (outCCCert) {adb_getKeysResponseType_set_CCcert(response, env, outCCCert);free(outCCCert);}
141  
-    if (outNCCert) {adb_getKeysResponseType_set_NCcert(response, env, outNCCert);free(outNCCert);}
142  
-  }
143  
-  
144  
-  adb_getKeysResponseType_set_userId(response, env, userId);
145  
-  adb_getKeysResponseType_set_correlationId(response, env, correlationId);
146  
-  adb_getKeysResponseType_set_return(response, env, status);
147  
-  adb_getKeysResponseType_set_serviceTag(response, env, service);
148  
-
149  
-  if (status == AXIS2_FALSE) {
150  
-    adb_getKeysResponseType_set_statusMessage(response, env, statusMessage);
151  
-  }
152  
-  
153  
-  ret = adb_GetKeysResponse_create(env);
154  
-  adb_GetKeysResponse_set_GetKeysResponse(ret, env, response);
155  
-  
156  
-  return(ret);
  128
+adb_GetKeysResponse_t *GetKeysMarshal(adb_GetKeys_t * getKeys, const axutil_env_t * env)
  129
+{
  130
+	adb_GetKeysResponse_t *ret = NULL;
  131
+	adb_getKeysResponseType_t *response = NULL;
  132
+
  133
+	adb_getKeysType_t *request = NULL;
  134
+
  135
+	int rc;
  136
+	axis2_bool_t status;
  137
+	char *userId, *correlationId, *service, statusMessage[256];
  138
+	char *outCCCert, *outNCCert;
  139
+
  140
+	request = adb_GetKeys_get_GetKeys(getKeys, env);
  141
+
  142
+	userId = adb_getKeysType_get_userId(request, env);
  143
+	correlationId = adb_getKeysType_get_correlationId(request, env);
  144
+	service = adb_getKeysType_get_serviceTag(request, env);
  145
+
  146
+	response = adb_getKeysResponseType_create(env);
  147
+
  148
+	status = AXIS2_TRUE;
  149
+	rc = doGetKeys(service, &outCCCert, &outNCCert);
  150
+	if (rc) {
  151
+		status = AXIS2_FALSE;
  152
+		snprintf(statusMessage, 255, "ERROR");
  153
+	} else {
  154
+		if (outCCCert) {
  155
+			adb_getKeysResponseType_set_CCcert(response, env, outCCCert);
  156
+			free(outCCCert);
  157
+		}
  158
+		if (outNCCert) {
  159
+			adb_getKeysResponseType_set_NCcert(response, env, outNCCert);
  160
+			free(outNCCert);
  161
+		}
  162
+	}
  163
+
  164
+	adb_getKeysResponseType_set_userId(response, env, userId);
  165
+	adb_getKeysResponseType_set_correlationId(response, env, correlationId);
  166
+	adb_getKeysResponseType_set_return(response, env, status);
  167
+	adb_getKeysResponseType_set_serviceTag(response, env, service);
  168
+
  169
+	if (status == AXIS2_FALSE) {
  170
+		adb_getKeysResponseType_set_statusMessage(response, env, statusMessage);
  171
+	}
  172
+
  173
+	ret = adb_GetKeysResponse_create(env);
  174
+	adb_GetKeysResponse_set_GetKeysResponse(ret, env, response);
  175
+
  176
+	return (ret);
157 177
 }
4  gatherlog/server-marshal.h
@@ -66,7 +66,7 @@
66 66
 #include "axis2_skel_EucalyptusGL.h"
67 67
 #include <handlers.h>
68 68
 
69  
-adb_GetLogsResponse_t *GetLogsMarshal(adb_GetLogs_t *getLogs, const axutil_env_t *env);
70  
-adb_GetKeysResponse_t *GetKeysMarshal(adb_GetKeys_t *getKeys, const axutil_env_t *env);
  69
+adb_GetLogsResponse_t *GetLogsMarshal(adb_GetLogs_t * getLogs, const axutil_env_t * env);
  70
+adb_GetKeysResponse_t *GetKeysMarshal(adb_GetKeys_t * getKeys, const axutil_env_t * env);
71 71
 
72 72
 #endif

0 notes on commit 2c03873

Please sign in to comment.
Something went wrong with that request. Please try again.