/******************************************************************** * FUNCTION main * * STDIN is input from the HTTP server through FastCGI wrapper * (sent to ncxserver) * STDOUT is output to the HTTP server (rcvd from ncxserver) * * RETURNS: * 0 if NO_ERR * 1 if error connecting or logging into ncxserver *********************************************************************/ int main (int argc, char **argv, char **envp) { int status = 0; yang_api_profile_t yang_api_profile; /* setup global vars used across all requests */ status = yang_api_init(&yang_api_profile); if (status != OK) { printf("Content-type: text/html\r\n\r\n" "<html><head><title>YANG-API echo</title></head>" "<body><h1>YANG-API init failed</h1></body></html>\n"); } /* temp: exit on all errors for now */ while (status == OK && FCGI_Accept() >= 0) { #ifdef DEBUG_TRACE printf("Content-type: text/html\r\n\r\n" "<html><head><title>YANG-API echo</title></head>" "<body><h1>YANG-API echo</h1>\n<pre>\n"); PrintEnv("Request environment", environ); #endif status = save_environment_vars(&yang_api_profile); if (status != OK) { continue; } status = setenv("REMOTE_USER", yang_api_profile.username, 0); if (status != 0) { continue; } #ifdef DEBUG_TRACE printf("start invoke netconf-subsystem-pro\n"); #endif status = run_subsystem_ex(PROTO_ID_YANGAPI, 3, argc, argv, envp, read_yangapi_buff, send_yangapi_buff, yang_api_profile.content_length); if (status != OK) { continue; } #ifdef DEBUG_TRACE printf("\n</pre></body></html>\n"); #endif cleanup_request(&yang_api_profile); } /* while */ yang_api_cleanup(&yang_api_profile); return status; } /* main */
/*ARGSUSED*/ static void door_server(void *cookie, char *argp, size_t arg_size, door_desc_t *dp, uint_t n_desc) { request_t req; xmlDocPtr x_doc; xmlChar *resp_buf = NULL; int ret, size = 0; pthread_t tid; thr_elem_t *thr; ucred_t *uc = NULL; if (ISNS_MGMT_REQUEST_RECEIVED_ENABLED()) { ISNS_MGMT_REQUEST_RECEIVED(); } if (door_ucred(&uc) != 0) { isnslog(LOG_DEBUG, "door_server", "door_ucred failed. errno: %d\n", errno); ret = build_result_message(&resp_buf, ERR_DOOR_UCRED_FAILED, &size); if (ret == ISNS_RSP_SUCCESSFUL) { (void) door_return((char *)resp_buf, size + 1, NULL, 0); /* Not reached */ } else { ret = ERR_DOOR_UCRED_FAILED; (void) door_return((void *)&ret, sizeof (ret), NULL, 0); /* Not reached */ } } isnslog(LOG_DEBUG, "door_server", "entered with request:\n %s\n", argp); if ((x_doc = xmlParseMemory(argp, arg_size)) != NULL) { isnslog(LOG_DEBUG, "door_server", "ParseMemory succeeded"); if ((ret = process_mgmt_request(x_doc, &req, uc)) == 0) { ret = build_mgmt_response(&resp_buf, req, &size); } else { ret = build_result_message(&resp_buf, ret, &size); } xmlFreeDoc(x_doc); cleanup_request(req); } else { ret = build_result_message(&resp_buf, ERR_XML_PARSE_MEMORY_FAILED, &size); } /* free the ucred */ ucred_free(uc); if (resp_buf) { tid = pthread_self(); if ((thr = match_entry(tid)) == NULL) { (void) add_entry(tid, resp_buf); } else { isnslog(LOG_DEBUG, "door_server", "free the previouly returned buffer %x on this thread\n", thr->doc); xmlFree(thr->doc); isnslog(LOG_DEBUG, "door_server", "store the currently allocated buffer %x on this thread\n", resp_buf); thr->doc = resp_buf; } isnslog(LOG_DEBUG, "door_server", "exiting with response:\n %s\n", (const char *)resp_buf); if (ISNS_MGMT_REQUEST_RESPONDED_ENABLED()) { ISNS_MGMT_REQUEST_RESPONDED(); } (void) door_return((char *)resp_buf, size + 1, NULL, 0); /* Not reached */ } isnslog(LOG_DEBUG, "door_server", "exiting only with error code %d\n", ret); if (ISNS_MGMT_REQUEST_RESPONDED_ENABLED()) { ISNS_MGMT_REQUEST_RESPONDED(); } (void) door_return((void *)&ret, sizeof (ret), NULL, 0); }