Skip to content
Permalink
Browse files

Fix scripts and code that use well-known tmp files.

  • Loading branch information...
BrendanCunningham committed Sep 18, 2015
1 parent 75a9a2f commit c5759e7b76f5bf844be6c6641cc1b356bbc83869
@@ -32,10 +32,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "hsm_config_srvr_api.h"

#define HSM_FM_SCK_PREFIX "/tmp/"
#define HSM_FM_SCK_PREFIX "/opt/opafm/"
#define HSM_FM_SCK_SM "sm_"
#define HSM_FM_SCK_PM "pm_"
#define HSM_FM_SCK_BM "bm_"
#define HSM_FM_SCK_FE "fe_"

typedef struct _fm_config_conx_hdl{
@@ -41,13 +41,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/stat.h>
#include <signal.h>
#include <time.h>
#include "hsm_config_client_api.h"
#include "hsm_config_client_data.h"
#include "hsm_com_client_data.h"

extern int getopt(int, char *const *, const char *);

@@ -1045,7 +1047,7 @@ int sm_skip_attr_write(p_fm_config_conx_hdlt hdl, fm_mgr_type_t mgr, int argc, c
}

int main(int argc, char *argv[]) {
p_fm_config_conx_hdlt hdl;
p_fm_config_conx_hdlt hdl = NULL;
int instance = 0;
fm_mgr_config_errno_t res;
char *rem_addr = NULL;
@@ -1087,26 +1089,46 @@ int main(int argc, char *argv[]) {
if((res = fm_mgr_config_init(&hdl,instance, rem_addr, community)) != FM_CONF_OK)
{
fprintf(stderr, "Failed to initialize the client handle: %d\n", res);
goto die_clean;
goto cleanup;
}

if((res = fm_mgr_config_connect(hdl)) != FM_CONF_OK)
{
fprintf(stderr, "Failed to connect: (%d) %s\n",res,fm_mgr_get_error_str(res));
goto die_clean;
goto cleanup;
}

for(i=0;i<commandListLen;i++){
if(strcmp(command,commandList[i].name) == 0){
return commandList[i].cmdPtr(hdl, commandList[i].mgr, (argc - optind), &argv[optind]);
res = commandList[i].cmdPtr(hdl, commandList[i].mgr, (argc - optind), &argv[optind]);
goto cleanup;
}
}

fprintf(stderr, "Command (%s) is not valid\n",command);
usage(argv[0]);
res = -1;

die_clean:
if (hdl) free(hdl);
cleanup:
if (hdl)
{
if (hdl->sm_hdl)
{
if (hdl->sm_hdl->c_path[0])
unlink(hdl->sm_hdl->c_path);
}
if (hdl->pm_hdl)
{
if (hdl->pm_hdl->c_path[0])
unlink(hdl->pm_hdl->c_path);
}
if (hdl->fe_hdl)
{
if (hdl->fe_hdl->c_path[0])
unlink(hdl->fe_hdl->c_path);
}
free(hdl);
}

return res;
}
@@ -245,6 +245,7 @@ unix_client_connect(hsm_com_client_hdl_t *hdl)
{
int fd, len;
struct sockaddr_un unix_addr;
hsm_com_errno_t res = HSM_COM_OK;

if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
{
@@ -257,8 +258,8 @@ unix_client_connect(hsm_com_client_hdl_t *hdl)

if(strlen(hdl->c_path) >= sizeof(unix_addr.sun_path))
{
close(fd);
return HSM_COM_PATH_ERR;
res = HSM_COM_PATH_ERR;
goto cleanup;
}

snprintf(unix_addr.sun_path, sizeof(unix_addr.sun_path), "%s", hdl->c_path);
@@ -269,17 +270,14 @@ unix_client_connect(hsm_com_client_hdl_t *hdl)

if(bind(fd, (struct sockaddr *)&unix_addr, len) < 0)
{
unlink(hdl->c_path);
close(fd);

return HSM_COM_BIND_ERR;
res = HSM_COM_BIND_ERR;
goto cleanup;
}

if(chmod(unix_addr.sun_path, S_IRWXU) < 0)
{
unlink(hdl->c_path);
close(fd);
return HSM_COM_CHMOD_ERR;
res = HSM_COM_CHMOD_ERR;
goto cleanup;
}

memset(&unix_addr,0,sizeof(unix_addr));
@@ -292,9 +290,8 @@ unix_client_connect(hsm_com_client_hdl_t *hdl)

if (connect(fd, (struct sockaddr *) &unix_addr, len) < 0)
{
unlink(hdl->c_path);
close(fd);
return HSM_COM_CONX_ERR;
res = HSM_COM_CONX_ERR;
goto cleanup;
}

hdl->client_fd = fd;
@@ -304,12 +301,14 @@ unix_client_connect(hsm_com_client_hdl_t *hdl)
if(unix_sck_send_conn(hdl, 2) != HSM_COM_OK)
{
hdl->client_state = HSM_COM_C_STATE_IN;
return HSM_COM_SEND_ERR;
res = HSM_COM_SEND_ERR;
}

return res;


return HSM_COM_OK;
cleanup:
close(fd);
return res;

}

@@ -98,6 +98,11 @@ hcom_client_init
strcpy(hdl->s_path,server_path);
strcpy(hdl->c_path,client_path);

if (mkstemp(hdl->c_path) == -1)
{
res = HSM_COM_PATH_ERR;
goto cleanup;
}

hdl->client_state = HSM_COM_C_STATE_IN;

@@ -52,13 +52,10 @@ fm_mgr_config_mgr_connect
char c_path[256];
char *mgr_prefix;
p_hsm_com_client_hdl_t *mgr_hdl;
pid_t pid;

memset(s_path,0,sizeof(s_path));
memset(c_path,0,sizeof(c_path));

pid = getpid();

switch ( mgr )
{
case FM_MGR_SM:
@@ -80,8 +77,7 @@ fm_mgr_config_mgr_connect
// Fill in the paths for the server and client sockets.
sprintf(s_path,"%s%s%d",HSM_FM_SCK_PREFIX,mgr_prefix,hdl->instance);

sprintf(c_path,"%s%s%d_C_%lu",HSM_FM_SCK_PREFIX,mgr_prefix,
hdl->instance, (long unsigned)pid);
sprintf(c_path,"%s%s%d_C_XXXXXX",HSM_FM_SCK_PREFIX,mgr_prefix,hdl->instance);

if ( *mgr_hdl == NULL )
{
@@ -147,17 +143,7 @@ fm_mgr_config_init
}
}


return res;


cleanup:

if ( hdl ) {
free(hdl);
hdl = NULL;
}

cleanup:
return res;
}

@@ -32,7 +32,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "hsm_config_client_api.h"

#define HSM_FM_SCK_PREFIX "/tmp/"
#define HSM_FM_SCK_PREFIX "/opt/opafm/"
#define HSM_FM_SCK_SM "sm_"
#define HSM_FM_SCK_PM "pm_"
#define HSM_FM_SCK_FE "fe_"
@@ -33,10 +33,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "hsm_config_api.h"
#include "snmp_com_api.h"

#define HSM_FM_SCK_PREFIX "/tmp/"
#define HSM_FM_SCK_PREFIX "/opt/opafm/"
#define HSM_FM_SCK_SM "sm_"
#define HSM_FM_SCK_PM "pm_"
#define HSM_FM_SCK_BM "bm_"
#define HSM_FM_SCK_FE "fe_"

typedef struct _fm_config_conx_hdl{
@@ -89,7 +89,7 @@ my_rc_status_all=0
my_rc_exit() { exit $my_rc_status_all; }
my_rc_status() { my_rc_status_all=$(($my_rc_status_all || $?)); }

temp=/tmp/ifsfm$$
temp=$(mktemp "/tmp/ifsfmXXXXX")

trap "rm -rf $tempdir; exit 1" 1 2 3 9 1

@@ -87,7 +87,7 @@ my_rc_status_all=0
my_rc_exit() { exit $my_rc_status_all; }
my_rc_status() { my_rc_status_all=$(($my_rc_status_all || $?)); }

temp=/tmp/ifsfm$$
temp=$(mktemp "/tmp/ifsfmXXXXX")
invalid_config()
{
local i

0 comments on commit c5759e7

Please sign in to comment.
You can’t perform that action at this time.