📄 sctmem.c
字号:
if (sct_elem.secure_messaging.command == CONCEALED) fprintf(stderr, "command == CONCEALED\n"); if (sct_elem.secure_messaging.command == COMBINED) fprintf(stderr, "command == COMBINED\n"); if (sct_elem.secure_messaging.response == SEC_NORMAL) fprintf(stderr, "response == SEC_NORMAL\n"); if (sct_elem.secure_messaging.response == AUTHENTIC) fprintf(stderr, "response == AUTHENTIC\n"); if (sct_elem.secure_messaging.response == CONCEALED) fprintf(stderr, "response == CONCEALED\n"); if (sct_elem.secure_messaging.response == COMBINED) fprintf(stderr, "response == COMBINED\n"); }#endif /* * Open port again */ if (p_elem->port_id > 0) { if ((COMinit(p_elem)) == -1) { aux_add_error(EOPENDEV, "Cannot open device", p_elem->port_name, char_n, proc); return (SCTerr(sw1, tp1_err)); }#ifdef SECSCTEST fprintf(stderr, "(PROCDAT) Port: %d for SCT: %d opened\n", p_elem->port_id, sct_id);#endif return (S_NOERR); /* reset already done */ } } else { aux_add_error(ESCPROCDATA, "SCA SCT configuration file invalid, is deleted!", config_file_name, char_n, proc); sca_delete_old_SCT_config(sct_id); free(config_file_name); return (0); } free(config_file_name); return(0);} /* end sca_read_SCT_config *//*--------------------------------------------------------------*//* *//* PROC sca_write_SCT_config *//* *//* DESCRIPTION *//* *//* Encrypt and write the configuration data for the specified *//* SCT into a file. *//* *//* 1. Check whether the SCT configuration data have been *//* changed. *//* If the main parts of the data haven't changed, nothing *//* will be done. *//* *//* 2. If the data have been changed: *//* Get key for the encryption of the SCT config data. *//* *//* Case 1: There is a key: *//* => The data for the specified SCT ("p_elem") are *//* encrypted with this key and written into a *//* configuration file. *//* Case 2: No key: *//* => nothing will be done. *//* *//* *//* IN DESCRIPTION *//* sct_id Identifier of the SCT for which *//* the SCT configuration data shall *//* be written. *//* p_elem Pointer to SCT specific structure*//* *//* OUT *//* *//* *//* RETURN DESCRIPTION *//* 0 ok *//* *//* CALLED FUNCTIONS DESCRIPTION *//* sca_get_SCT_config_fname() Get name of SCT configuration *//* file. *//* sca_get_process_key() Get process key for encryption /*//* decryption of SCT config. *//* SCT_config_changed() Check whether SCT config data *//* have been changed. *//* aux_add_error() Add error to error stack. *//* *//*--------------------------------------------------------------*/int sca_write_SCT_config(sct_id, p_elem) int sct_id; struct s_portparam *p_elem; { unsigned int secsc_errno; char *process_key; char *config_file_name = ""; int fd_proc_data; static int old_sctid = 0; struct s_help_portparam sct_elem; static struct s_help_portparam last_sct_elem; char *proc = "sca_write_SCT_config"; secsc_errno = NOERR;/********************************************************************************//* * If the SCT configuration data haven't been changed, the data will * not be written to the SCT configuration file */ if (old_sctid == sct_id) if (SCT_config_changed(&last_sct_elem, p_elem) == FALSE) return(0); old_sctid = sct_id;#ifdef SECSCTEST fprintf(stderr, "SECSC-Function: %s\n", proc);#endif/********************************************************************************//* * Get encryption key for the SCT configuration data */ process_key = sca_get_process_key(); if (process_key == CNULL) { /* No key available => error */ aux_add_error(ESCPROCKEY, "No process key available!", CNULL, 0, proc); return (0); }#ifdef SECSCTEST fprintf(stderr, "process key from get_process_key: %s\n", process_key);#endif/********************************************************************************//* * Get name of SCT configuration file: */ config_file_name = sca_get_SCT_config_fname (sct_id); if (config_file_name == CNULL) { aux_add_error(ESCPROCDATA, "Cannot get name of SCT configuration file!", CNULL, 0, proc); free(process_key); return (0); }/********************************************************************************//* * Open SCT configuration file */ if ((fd_proc_data = open(config_file_name, O_WRONLY | O_CREAT, FILEMASK)) < 0) { aux_add_error(ESCPROCDATA, "Cannot open SCT configuration file!", config_file_name, char_n, proc); free(process_key); free(config_file_name); return (0); } chmod(config_file_name, FILEMASK); free(config_file_name); /********************************************************************************//* * Encrypt and write SCT configuration data */ sct_elem.bwt = p_elem->bwt; strcpy (sct_elem.port_name, p_elem->port_name); sct_elem.cwt = p_elem->cwt; sct_elem.baud = p_elem->baud; sct_elem.databits = p_elem->databits; sct_elem.stopbits = p_elem->stopbits; sct_elem.parity = p_elem->parity; sct_elem.dataformat = p_elem->dataformat; sct_elem.tpdusize = p_elem->tpdusize; sct_elem.apdusize = p_elem->apdusize; sct_elem.edc = p_elem->edc; sct_elem.protocoltype = p_elem->protocoltype; sct_elem.chaining = p_elem->chaining; sct_elem.ns = p_elem->ns; sct_elem.rsv = p_elem->rsv; sct_elem.sad = p_elem->sad; sct_elem.dad = p_elem->dad; if (p_elem->schistory) strcpy (sct_elem.schistory, p_elem->schistory); else sct_elem.schistory[0] = '\0'; sct_elem.port_id = p_elem->port_id; sct_elem.first = p_elem->first; sct_elem.ssc = p_elem->ssc; sct_elem.sc_request = p_elem->sc_request; sct_elem.setmode = p_elem->setmode; sct_elem.session_key.subjectAI = p_elem->session_key.subjectAI; sct_elem.session_key.subjectkey.bits = p_elem->session_key.subjectkey.bits; sct_elem.session_key.subjectkey.nbits = p_elem->session_key.subjectkey.nbits; sct_elem.secure_messaging.response = p_elem->secure_messaging.response; sct_elem.secure_messaging.command = p_elem->secure_messaging.command; /* * The values of sct_elem will be encrypted by function "write_enc()" */ if ((write_enc(fd_proc_data, &sct_elem, sizeof(struct s_help_portparam), process_key)) < 0) { aux_add_error(ESCPROCDATA, "Cannot write configuration data for SCT! ", CNULL, char_n, proc); close_enc(fd_proc_data); free(process_key); return (0); } close_enc(fd_proc_data); free(process_key); /********************************************************************************//* * Save values of p_elem */ last_sct_elem.bwt = p_elem->bwt; strcpy (last_sct_elem.port_name, p_elem->port_name); last_sct_elem.cwt = p_elem->cwt; last_sct_elem.baud = p_elem->baud; last_sct_elem.databits = p_elem->databits; last_sct_elem.stopbits = p_elem->stopbits; last_sct_elem.parity = p_elem->parity; last_sct_elem.dataformat = p_elem->dataformat; last_sct_elem.tpdusize = p_elem->tpdusize; last_sct_elem.apdusize = p_elem->apdusize; last_sct_elem.edc = p_elem->edc; last_sct_elem.protocoltype = p_elem->protocoltype; last_sct_elem.chaining = p_elem->chaining; last_sct_elem.ns = p_elem->ns; last_sct_elem.rsv = p_elem->rsv; last_sct_elem.sad = p_elem->sad; last_sct_elem.dad = p_elem->dad; if (p_elem->schistory) strcpy (last_sct_elem.schistory, p_elem->schistory); else last_sct_elem.schistory[0] = '\0'; last_sct_elem.port_id = p_elem->port_id; last_sct_elem.first = p_elem->first; last_sct_elem.ssc = p_elem->ssc; last_sct_elem.sc_request = p_elem->sc_request; last_sct_elem.setmode = p_elem->setmode; last_sct_elem.session_key.subjectAI = p_elem->session_key.subjectAI; last_sct_elem.session_key.subjectkey.bits = p_elem->session_key.subjectkey.bits; last_sct_elem.session_key.subjectkey.nbits = p_elem->session_key.subjectkey.nbits; last_sct_elem.secure_messaging.response = p_elem->secure_messaging.response; last_sct_elem.secure_messaging.command = p_elem->secure_messaging.command; return(0);} /* end sca_write_SCT_config *//*--------------------------------------------------------------*//* *//* PROC sca_delete_old_SCT_config *//* *//* DESCRIPTION *//* *//* Delete old SCT specific SCT configuration file. *//* *//* *//* IN DESCRIPTION *//* sct_id Identifier of the SCT for which *//* the SCT configuration file shall *//* be deleted. *//* *//* OUT *//* *//* *//* RETURN DESCRIPTION *//* 0 ok (file deleted or file does *//* not exist) */ /* -1 error *//* *//* CALLED FUNCTIONS DESCRIPTION *//* sca_get_SCT_config_fname() Get name of SCT configuration *//* file. *//* aux_add_error() Add error to error stack. *//* *//*--------------------------------------------------------------*/staticint sca_delete_old_SCT_config(sct_id)int sct_id;{ unsigned int secsc_errno; char *config_file_name = ""; char *proc = "sca_delete_old_SCT_config"; secsc_errno = NOERR;#ifdef SECSCTEST fprintf(stderr, "SECSC-Function: %s\n", proc);#endif/********************************************************************************//* * Get name of SCT configuration file: */ config_file_name = sca_get_SCT_config_fname (sct_id); if (config_file_name == CNULL) { aux_add_error(ESCPROCDATA, "Cannot get name of SCT configuration file!", CNULL, 0, proc); return (-1); }/********************************************************************************//* * Delete old proc data files */ if (unlink(config_file_name)) { if (errno != ENOENT) { aux_add_error(ESCPROCDATA, "Cannot delete SCT configuration file!", config_file_name, char_n, proc); free(config_file_name); return (-1); } } free(config_file_name); return(0);} /* end sca_delete_old_SCT_config *//*--------------------------------------------------------------*//* *//* PROC sca_get_SCT_config_fname *//* *//* DESCRIPTION *//* *//* Compose and return name of the SCT configuration file for *//* the specified SCT: *//* *//* Structure: *//* Home directory || SCA_SCT_CONFIG_name || sct_id *//* *//* *//* The calling routine has to release the allocated memory. *//* *//* IN DESCRIPTION *//* sct_id Identifier of the SCT. *//* *//* OUT *//* *//* *//* RETURN DESCRIPTION *//* <> CNULL ptr to name of file *//* CNULL error *//* *//* CALLED FUNCTIONS DESCRIPTION *//* *//*--------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -