int s_open(IncomingRequest *inc_request) { FsResponse response; FsOpenC data_c = inc_request->request.data.open; int lock_result; int server_handler = data_c.server_handler; if (session_check_if_exist(server_handler) == -1) { response.answer= EC_SESSION_TIMED_OUT; response.data.open.status = -1; VDP1 ("Session timed out with: %d\n", server_handler); status = sendto(sockd, &response, sizeof(FsResponse), 0,(struct sockaddr*) &(inc_request->client_addr), inc_request->client_addr_len); return -1; } char *file_name = (char *) calloc(data_c.name_len, sizeof(char)); strncpy(file_name, data_c.name, data_c.name_len); VDP3("Incoming OPEN request: %s, len = %zu (flags: %d)\n", file_name, data_c.name_len, data_c.flags); if (inc_request->request.data.open.flags == O_RDONLY) lock_result = session_lock_file(inc_request->request.data.open.server_handler, file_name, FLOCK_SH); else lock_result = session_lock_file(inc_request->request.data.open.server_handler, file_name, FLOCK_EX); if(lock_result < 0) { /* Nie udalo sie dostac blokady na plik - trzeba powiadomic o tym klienta. */ VDP0("Lock failed, request turned down.\n"); response.data.open.status = -1; response.answer = EF_FILE_BLOCKED; } else { VDP0("Lock accepted, request accepted.\n"); VDP2("Attempting to open %s file in %d mode...\n", file_name, data_c.flags); int fh = open(file_name, data_c.flags); if(fh == -1) { VDP1("File %s cannot be opened.\n", file_name); session_unlock_file(inc_request->request.data.open.server_handler, lock_result); response.data.open.status = -1; response.answer = EF_NOT_FOUND; response.data.open.fd = -1; } else { VDP1("File %s opened successfully. \n", file_name); status = session_set(inc_request->request.data.open.server_handler, lock_result, fh); response.data.open.status = lock_result; response.answer = IF_OK; response.data.open.fd = lock_result; } } free(file_name); return sendto(sockd, &response, sizeof(FsResponse), 0,(struct sockaddr*) &(inc_request->client_addr), inc_request->client_addr_len); }
PyObject *ekg_session_set(ekg_sessionObj * self, PyObject * key, PyObject * value) { session_t * s; const char *name = PyString_AsString(key); s = session_find(self->name); debug("[python] Setting '%s' option to '%s' for session %s\n", name, PyString_AsString(value), self->name); if (session_is_var(s, name) != 1) { PyErr_SetString(PyExc_LookupError, "unknown variable"); return NULL; } if (PyInt_Check(value)) { session_set(s, name, itoa(PyInt_AsLong(value))); } else { session_set(s, name, PyString_AsString(value)); } config_changed = 1; Py_INCREF(Py_None); return Py_None; }
char *NetGuard_Command_Input_WH8::doset(char *ip, char* oid, char *value){ struct snmp_session *snmp_sess; char *buffer, *tmpresult; char *result; buffer = NULL; result = NULL; snmp_sess = session_open(ip, community.c_str()); #ifdef debug printf("query: %s\n",oid); printf("value: %s\n",value); #endif buffer = session_set(snmp_sess,oid,value); #ifdef debug printf("query Result: %s\n",buffer); #endif if (buffer != NULL){ if (strstr(buffer,": ") != NULL) { //suche in der Antwort nach dem AntwortString tmpresult = buffer; while (tmpresult[0] != ':') { tmpresult++; } tmpresult++; tmpresult++; #ifdef debug printf("query Result: %s\n",buffer); #endif } else tmpresult = buffer; result = strdup(tmpresult); free(buffer); #ifdef debug printf("Result: %s \n", result); #endif } else { #ifdef debug printf("Cant Exec Command got null reply\n"); #endif }; session_close(snmp_sess); return result; }
static char *sasl_auth_digest_md5(session_t *s, const char *username, const char *password, const char *nonce, const char *realm) { jabber_private_t *j = s->priv; char tmp_cnonce[32]; const char *auth_resp; char *encoded, *cnonce, *temp;; int i; if (!realm) realm = j->server; /* generate random number using high-order bytes man 3 rand() */ for (i=0; i < sizeof(tmp_cnonce); i++) tmp_cnonce[i] = (char) (256.0*rand()/(RAND_MAX+1.0)); cnonce = base64_encode(tmp_cnonce, sizeof(tmp_cnonce)); temp = g_strdup_printf(":xmpp/%s", realm); auth_resp = challenge_digest(username, password, nonce, cnonce, temp, realm); g_free(temp); session_set(s, "__sasl_excepted", auth_resp); temp = g_strdup_printf("AUTHENTICATE:xmpp/%s", realm); auth_resp = challenge_digest(username, password, nonce, cnonce, temp, realm); g_free(temp); temp = g_strdup_printf( "username=\"%s\",realm=\"%s\",nonce=\"%s\",cnonce=\"%s\",nc=00000001," "digest-uri=\"xmpp/%s\",qop=auth,response=%s,charset=utf-8", username, realm, nonce, cnonce, realm, auth_resp); g_free(cnonce); encoded = base64_encode(temp, xstrlen(temp)); /* XXX base64_encoded() CHANGED!! str->len+1 ? */ g_free(temp); return encoded; }
/** * 设置要保存在 session 中的字符串 * * @param const char* name 字符串的名字 * @param const char* string 字符串 * * @return int 成功返回0,失败返回非0值 */ int session_set(const char* name, const char* string) { int i; SESSION_ITEM_LIST tmp_list = NULL; size_t buffer_size; #ifdef DEBUG fprintf(cgiOut, "session_set(), session file:%s\n", g_session_data->session_filename); #endif for (i = 0; i < g_session_data->max_index; i++) { if (g_session_data->items[i].name == NULL) { // 找到空闲的项目 g_session_data->items[i].name = (char*) malloc( (strlen(name) + 1) * sizeof(char)); strcpy(g_session_data->items[i].name, name); g_session_data->items[i].string = (char*) malloc( (strlen(string) + 1) * sizeof(char)); strcpy(g_session_data->items[i].string, string); g_session_data->count++; return 0; } } // 需要扩充容量 i = g_session_data->max_index + (g_session_data->max_index / 2) + 2; buffer_size = i * sizeof(SESSION_ITEM); tmp_list = (SESSION_ITEM*) malloc(buffer_size); memset(tmp_list, 0, buffer_size); memcpy(tmp_list, g_session_data->items, g_session_data->max_index * sizeof(SESSION_ITEM)); free(g_session_data->items); g_session_data->items = tmp_list; g_session_data->max_index = i; return session_set(name, string); }
/** * 显示登录页面以及处理用户登录 */ int login_process() { char* username = NULL; char* password = NULL; char* buffer = NULL; int field_buffer_size = 0; REPLACEABLE_TAG_LIST tag_list = (REPLACEABLE_TAG_LIST) malloc( sizeof(REPLACEABLE_TAG) * 2); // 获取用户提交的用户名和密码,如果没有提交数据,则 username 和 password 为空字符串 cgiFormStringSpaceNeeded("username", &field_buffer_size); username = (char*) malloc(field_buffer_size); memset(username, 0, field_buffer_size); cgiFormString("username", username, field_buffer_size); cgiFormStringSpaceNeeded("password", &field_buffer_size); password = (char*) malloc(field_buffer_size); cgiFormString("password", password, field_buffer_size); if (strcmp(username, g_login_username) == 0 && strcmp(password, g_login_password) == 0) { // 登录验证通过,设置 session 数据后重定向浏览器 session_set("USERNAME", g_login_username); session_write_close(); cgiHeaderLocation(cgiScriptName); free(username); free(password); return 0; } // 输出 ContentType header // 作为 CGI 程序必须输出这个 header,否则会导致 500 错误 fprintf(cgiOut, "Pragma: no-cache\n"); cgiHeaderContentType("text/html"); // 显示登录页面 tag_list[0].tag = "{%ERROR_MESSAGE%}"; if (strlen(username) != 0 || strlen(password) != 0) { tag_list[0].value = "您输入的用户名或者密码错误。"; } else { tag_list[0].value = ""; } tag_list[1].tag = "{%USERNAME%}"; tag_list[1].value = username; buffer = read_template(g_login_template); if (buffer == NULL) { fprintf(cgiOut, "Warning: Can't read template file: %s.<br />\n", g_login_template); free(username); free(password); return -1; } parse_template(&buffer, tag_list, 2); fprintf(cgiOut, "%s", buffer); free(buffer); free(username); free(password); // session_destroy(); return 0; }