📄 xsupgui_request7.c
字号:
if (t == NULL)
{
if (myconns != NULL) free(myconns);
done = IPC_ERROR_BAD_RESPONSE;
goto finish_enum_connections;
}
content = xmlNodeGetContent(t);
if ((content != NULL) && (strlen(content) > 0))
{
myconns[i].flags = atoi(content);
free(content);
}
t = xsupgui_request_find_node(n->children, "Device_Description");
if (t == NULL)
{
if (myconns != NULL) free(myconns);
done = IPC_ERROR_BAD_RESPONSE;
goto finish_enum_connections;
}
myconns[i].dev_desc = xmlNodeGetContent(t);
t = xsupgui_request_find_node(n->children, "Priority");
if (t == NULL)
{
if (myconns != NULL) free(myconns);
done = IPC_ERROR_BAD_RESPONSE;
goto finish_enum_connections;
}
content = xmlNodeGetContent(t);
if (content != NULL)
{
myconns[i].priority = atoi(content);
free(content);
}
t = xsupgui_request_find_node(n->children, "Encryption");
if (t == NULL)
{
if (myconns != NULL) free(myconns);
done = IPC_ERROR_BAD_RESPONSE;
goto finish_enum_connections;
}
content = xmlNodeGetContent(t);
if (content != NULL)
{
myconns[i].encryption = atoi(content);
free(content);
}
t = xsupgui_request_find_node(n->children, "Authentication");
if (t == NULL)
{
if (myconns != NULL) free(myconns);
done = IPC_ERROR_BAD_RESPONSE;
goto finish_enum_connections;
}
content = xmlNodeGetContent(t);
if ((content != NULL) && (strlen(content) > 0))
{
myconns[i].auth_type = atoi(content);
free(content);
}
n = n->next;
}
(*connections) = myconns;
done = REQUEST_SUCCESS;
finish_enum_connections:
if (doc) xmlFreeDoc(doc);
if (retdoc) xmlFreeDoc(retdoc);
return done;
}
/**
* \brief Free a poss_conn_enum that was allocated by one of the request functions.
*
* @param[in] data A double dereferenced pointer to the memory that was allocated by
* one of the xsupgui_request_* functions.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_FAILURE on failure
**/
int xsupgui_request_free_poss_conn_enum(poss_conn_enum **data)
{
int i = 0;
poss_conn_enum *cenum = NULL;
cenum = (*data);
if (cenum == NULL) return REQUEST_SUCCESS;
i = 0;
while (cenum[i].name != NULL)
{
if (cenum[i].dev_desc != NULL) free(cenum[i].dev_desc);
if (cenum[i].name != NULL) free(cenum[i].name);
if (cenum[i].ssid != NULL) free(cenum[i].ssid);
i++;
}
free((*data));
(*data) = NULL;
return REQUEST_SUCCESS;
}
/**
* \brief Request that the supplicant unbind a profile and connection from the context.
*
* @param[in] device The OS specific name of the device that we want to unbind profile/connection data.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_TIMEOUT on timeout
* \retval >299 on other error
*
* \warning Unbinding a connection without sending a disassociate and/or logoff will leave
* your connection in a limbo state. It shouldn't have any bad side effects, but may
* have some strange error messages as a result.
**/
int xsupgui_request_unbind_connection(char *device)
{
xmlDocPtr doc = NULL;
xmlDocPtr retdoc = NULL;
xmlNodePtr n = NULL, t = NULL;
int done = 0, err = 0;
char *temp = NULL;
doc = xsupgui_xml_common_build_msg();
if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;
n = xmlDocGetRootElement(doc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
goto cdone;
}
t = xmlNewChild(n, NULL, "Unbind_Connection", NULL);
if (t == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto cdone;
}
xsupgui_xml_common_convert_amp(device, &temp);
if (xmlNewChild(t, NULL, "Interface", temp) == NULL)
{
done = IPC_ERROR_INVALID_PARAMETERS;
free(temp);
goto cdone;
}
free(temp);
err = xsupgui_request_send(doc, &retdoc);
if (err != REQUEST_SUCCESS)
{
done = err;
goto cdone;
}
// Otherwise, parse it and see if we got what we wanted.
err = xsupgui_request_check_exceptions(retdoc);
if (err != 0)
{
done = err;
goto cdone;
}
n = xmlDocGetRootElement(retdoc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
goto cdone;
}
// If we get here, then we know that the document passed the
// validation tests imposed. So, we need to see if we got the result
// we wanted.
n = n->children;
if (xsupgui_request_find_node(n, "ACK") != NULL)
{
done = REQUEST_SUCCESS;
}
else
{
done = IPC_ERROR_NOT_ACK;
}
cdone:
if (doc != NULL) xmlFreeDoc(doc);
if (retdoc != NULL) xmlFreeDoc(retdoc);
return done;
}
/**
* \brief Request that the supplicant rename a configuration item. (Connection/Profile/Trusted Server)
*
* @param[in] itemtype The IPC command for the change.
* @param[in] oldname The current name of item.
* @param[in] newname The name the item should be changed to.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_TIMEOUT on timeout
* \retval >299 on other error
**/
int xsupgui_request_rename_something(char *itemtype, char *oldname, char *newname)
{
xmlDocPtr doc = NULL;
xmlDocPtr retdoc = NULL;
xmlNodePtr n = NULL, t = NULL;
int done = 0, err = 0;
char *temp = NULL;
if ((itemtype == NULL) || (oldname == NULL) || (newname == NULL))
return IPC_ERROR_INVALID_PARAMETERS;
doc = xsupgui_xml_common_build_msg();
if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;
n = xmlDocGetRootElement(doc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
goto cdone;
}
t = xmlNewChild(n, NULL, itemtype, NULL);
if (t == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto cdone;
}
xsupgui_xml_common_convert_amp(oldname, &temp);
if (xmlNewChild(t, NULL, "Old_Name", temp) == NULL)
{
done = IPC_ERROR_INVALID_PARAMETERS;
free(temp);
goto cdone;
}
free(temp);
xsupgui_xml_common_convert_amp(newname, &temp);
if (xmlNewChild(t, NULL, "New_Name", temp) == NULL)
{
done = IPC_ERROR_INVALID_PARAMETERS;
free(temp);
goto cdone;
}
free(temp);
err = xsupgui_request_send(doc, &retdoc);
if (err != REQUEST_SUCCESS)
{
done = err;
goto cdone;
}
// Otherwise, parse it and see if we got what we wanted.
err = xsupgui_request_check_exceptions(retdoc);
if (err != 0)
{
done = err;
goto cdone;
}
n = xmlDocGetRootElement(retdoc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
goto cdone;
}
// If we get here, then we know that the document passed the
// validation tests imposed. So, we need to see if we got the result
// we wanted.
n = n->children;
if (xsupgui_request_find_node(n, "ACK") != NULL)
{
done = REQUEST_SUCCESS;
}
else
{
done = IPC_ERROR_NOT_ACK;
}
cdone:
if (doc != NULL) xmlFreeDoc(doc);
if (retdoc != NULL) xmlFreeDoc(retdoc);
return done;
}
/**
* \brief Request that we change the name of a connection.
*
* @param[in] oldname The current name of the connection.
* @param[in] newname The name that we want the connection to be changed to.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_TIMEOUT on timeout
* \retval >299 on other error
**/
int xsupgui_request_rename_connection(char *oldname, char *newname)
{
return xsupgui_request_rename_something("Rename_Connection", oldname, newname);
}
/**
* \brief Request that we change the name of a profile.
*
* @param[in] oldname The current name of the profile.
* @param[in] newname The name that we want the profile to be changed to.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_TIMEOUT on timeout
* \retval >299 on other error
**/
int xsupgui_request_rename_profile(char *oldname, char *newname)
{
return xsupgui_request_rename_something("Rename_Profile", oldname, newname);
}
/**
* \brief Request that we change the name of a trusted server.
*
* @param[in] oldname The current name of the trusted server.
* @param[in] newname The name that we want the trusted server to be changed to.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_TIMEOUT on timeout
* \retval >299 on other error
**/
int xsupgui_request_rename_trusted_server(char *oldname, char *newname)
{
return xsupgui_request_rename_something("Rename_Trusted_Server", oldname, newname);
}
/**
* \brief Given an interface name, get it's link state.
*
* @param[in] intname The OS specific interface name that we need to get information
* for.
* @param[out] connname The interface connection name.
*
* \retval >299 the request to the supplicant failed.
* \retval REQUEST_TIMEOUT the request timed out
* \retval REQUEST_SUCCESS the request succeeded.
**/
int xsupgui_request_get_link_state_from_int(char *intname, int *state)
{
xmlDocPtr doc = NULL;
xmlDocPtr retdoc = NULL;
xmlNodePtr n = NULL, t = NULL;
char *value = NULL;
int retval = REQUEST_SUCCESS;
int err = 0;
char *temp = NULL;
if ((intname == NULL) || (state == NULL)) return IPC_ERROR_INVALID_PARAMETERS;
(*state) = NULL;
doc = xsupgui_xml_common_build_msg();
if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;
n = xmlDocGetRootElement(doc);
if (n == NULL)
{
retval = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
goto done;
}
t = xmlNewChild(n, NULL, "Get_Link_State_From_Interface", NULL);
if (t == NULL)
{
retval = IPC_ERROR_CANT_CREATE_REQUEST;
goto done;
}
xsupgui_xml_common_convert_amp(intname, &temp);
if (xmlNewChild(t, NULL, "Interface", temp) == NULL)
{
retval = IPC_ERROR_CANT_CREATE_INT_NODE;
free(temp);
goto done;
}
free(temp);
err = xsupgui_request_send(doc, &retdoc);
if (err != REQUEST_SUCCESS)
{
retval = err;
goto done;
}
err = xsupgui_request_check_exceptions(retdoc);
if (err != REQUEST_SUCCESS)
{
retval = err;
goto done;
}
n = xmlDocGetRootElement(retdoc);
if (n == NULL)
{
retval = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
goto done;
}
n = xsupgui_request_find_node(n->children, "Link_State_From_Interface");
if (n == NULL)
{
retval = IPC_ERROR_BAD_RESPONSE;
goto done;
}
n = n->children;
t = xsupgui_request_find_node(n, "Link_State");
if (t == NULL)
{
retval = IPC_ERROR_BAD_RESPONSE_DATA;
goto done;
}
value = xmlNodeGetContent(t);
(*state) = atoi(value);
free(value);
done:
xmlFreeDoc(doc);
xmlFreeDoc(retdoc);
return retval;
}
/**
* \brief Request that the engine create a trouble ticket dump.
*
* @param[in] filename The file name (ending in .zip) that should be created.
* @param[in] scratchdir A scratch directory that should be used for plug-ins to create dump data.
* @param[in] overwrite If we should overwrite the .zip file if it exists, or return an error.
*
* \retval >299 the request to the supplicant failed.
* \retval REQUEST_TIMEOUT the request timed out
* \retval REQUEST_SUCCESS the request succeeded.
**/
int xsupgui_request_create_trouble_ticket_file(char *filename, char *scratchdir, int overwrite)
{
xmlDocPtr doc = NULL;
xmlDocPtr retdoc = NULL;
xmlNodePtr n = NULL, t = NULL;
char tempstatic[100];
char *temp = NULL;
int retval = REQUEST_SUCCESS;
int err = 0;
doc = xsupgui_xml_common_build_msg();
if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;
n = xmlDocGetRootElement(doc);
if (n == NULL)
{
retval = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
goto done;
}
t = xmlNewChild(n, NULL, "Create_Trouble_Ticket", NULL);
if (t == NULL)
{
retval = IPC_ERROR_CANT_CREATE_REQUEST;
goto done;
}
xsupgui_xml_common_convert_amp(scratchdir, &temp);
if (xmlNewChild(t, NULL, "Temp_Data_Path", temp) == NULL)
{
retval = IPC_ERROR_CANT_CREATE_REQUEST;
free(temp);
goto done;
}
free(temp);
xsupgui_xml_common_convert_amp(filename, &temp);
if (xmlNewChild(t, NULL, "Trouble_Ticket_File", temp) == NULL)
{
retval = IPC_ERROR_CANT_CREATE_REQUEST;
free(temp);
goto done;
}
free(temp);
sprintf((char *)&tempstatic, "%d", overwrite);
if (xmlNewChild(t, NULL, "Overwrite", tempstatic) == NULL)
{
retval = IPC_ERROR_CANT_CREATE_REQUEST;
goto done;
}
err = xsupgui_request_send(doc, &retdoc);
if (err != REQUEST_SUCCESS)
{
retval = err;
goto done;
}
// Check if we got errors.
err = xsupgui_request_check_exceptions(retdoc);
if (err != 0)
{
retval = err;
goto done;
}
retval = xsupgui_request_is_ack(retdoc);
done:
xmlFreeDoc(doc);
xmlFreeDoc(retdoc);
return retval;
}
/**
* \brief Request the association type that is currently in use.
*
* @param[in] device The OS specific device name that we want to get the association type
* from.
* @param[out] capabilities A bitmap that contains information about the capabilities of an interface.
*
* \retval REQUEST_FAILURE on failure
* \retval REQUEST_SUCCESS on success
* \retval >299 on other error.
**/
int xsupgui_request_get_interface_capabilities(char *device, int *capabilities)
{
return xsupgui_request_get_some_value(device, "Get_Interface_Capabilities", "Interface_Capabilities",
"Capabilities", capabilities);
}
/**
* \brief Request that the engine install a new root CA certificate to the certificate store.
*
* @param[in] filename The file name (ending in .zip) that should be created.
*
* \retval >299 the request to the supplicant failed.
* \retval REQUEST_TIMEOUT the request timed out
* \retval REQUEST_SUCCESS the request succeeded.
**/
int xsupgui_request_add_root_ca_certificate(char *filename)
{
xmlDocPtr doc = NULL;
xmlDocPtr retdoc = NULL;
xmlNodePtr n = NULL, t = NULL;
char tempstatic[100];
char *temp = NULL;
int retval = REQUEST_SUCCESS;
int err = 0;
doc = xsupgui_xml_common_build_msg();
if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;
n = xmlDocGetRootElement(doc);
if (n == NULL)
{
retval = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
goto done;
}
t = xmlNewChild(n, NULL, "Add_Cert_to_Store", NULL);
if (t == NULL)
{
retval = IPC_ERROR_CANT_CREATE_REQUEST;
goto done;
}
xsupgui_xml_common_convert_amp(filename, &temp);
if (xmlNewChild(t, NULL, "Cert_Path", temp) == NULL)
{
retval = IPC_ERROR_CANT_CREATE_REQUEST;
free(temp);
goto done;
}
free(temp);
err = xsupgui_request_send(doc, &retdoc);
if (err != REQUEST_SUCCESS)
{
retval = err;
goto done;
}
// Check if we got errors.
err = xsupgui_request_check_exceptions(retdoc);
if (err != 0)
{
retval = err;
goto done;
}
retval = xsupgui_request_is_ack(retdoc);
done:
xmlFreeDoc(doc);
xmlFreeDoc(retdoc);
return retval;
}
/**
* \brief Request the TNC connection ID for an interface.
*
* @param[in] device The OS specific device name that we want to get the association type
* from.
* @param[out] tnc_conn_id The TNC connection ID for the interface.
*
* \retval REQUEST_FAILURE on failure
* \retval REQUEST_SUCCESS on success
* \retval >299 on other error.
**/
int xsupgui_request_get_tnc_conn_id(char *device, unsigned int *tnc_conn_id)
{
return xsupgui_request_get_some_value(device, "Get_TNC_Conn_ID", "TNC_Conn_ID",
"Conn_ID", tnc_conn_id);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -