// //Fill out the ADSL ctAR5211BitErrorTable // void adslMibHelper_fillctAR5211BitErrorTable(pADSL_MIB_CTAR5211BITERRORTABLE pTable) { char tmp[32] = {0}; char *end; pADSL_MIB_CTAR5211BITERRORTABLE p = pTable; p->pTableBeginning = pTable; p->ifIndex = getAdslIfIndex(); /*Init the table value*/ p->ctTxBiterror = 0; p->ctRxBiterror = 0; /* 0. get TX Bit Error Count */ memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOSHOW_NODE, AR5211_TX_BIRERR_CNT, tmp); p->ctTxBiterror = strtoul(tmp, &end, 0); /* 1. get RX Bit Error Count */ memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOSHOW_NODE, AR5211_RX_BIRERR_CNT, tmp); p->ctRxBiterror = strtoul(tmp, &end, 0); p->next = NULL; }
unsigned long getAR5211AdslInfo(char *attr_total, char *attr_curr) { char tmp[32] = {0}; char status[8] = {0}; char *end; unsigned long total= 0; /* 0. get adsl status */ tcapi_get(INFOADSL_NODE, ADSL_STATUS_ATTR, status); /* 1. get total Value */ memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOTOTAL_NODE, attr_total, tmp); total = strtoul(tmp, &end, 0); //tcdbg_printf("\n==>fillctAR5211TxInfoTable, 11 %s = %lu, %s\n", attr_total, total, tmp); if(0 == strcmp(status, ADSL_STATUS_UP)) { memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOSHOW_NODE, attr_curr, tmp); total += strtoul(tmp, &end, 0); //tcdbg_printf("\n==>fillctAR5211TxInfoTable, 22 %s = %lu, %s\n", attr_total, total, tmp); } return total; }
/* * Fill out the ADSL adslAturChanIntervalTable */ void adslMibHelper_filladslAturChanIntervalTable (pADSL_MIB_ADSLATURCHANINTERVALTABLE pTable) { int numOfInterval, i; int index; int validInterval; char tmp[32] = {0}; char prev[32] = {0}; unsigned long intervalValue = 0; char attrname[48] = {0}; char *end; pADSL_MIB_ADSLATURCHANINTERVALTABLE p = pTable; index = getAdslIfIndex(); /* the max interval we support */ numOfInterval = ADSLMIB_CHANPERFINTERVAL_MAXNUM; tcapi_get(INFOSHOW_NODE, ATUR_CHAN_PERF_VALID_ITLS, tmp); validInterval = atoi(tmp); for (i=0; i<numOfInterval; i++) { p->pTableBeginning = pTable; p->ifIndex = index; p->adslAturChanIntervalNumber = i+1; if (validInterval > i) { memset(attrname, 0, sizeof(attrname)); sprintf(attrname, ATURCHANRXBLKSITL_ATTR, i); tcapi_get(INFOINTERVRLST_NODE, attrname, prev); memset(attrname, 0, sizeof(attrname)); sprintf(attrname, ATURCHANRXBLKSITL_ATTR, i+1); tcapi_get(INFOINTERVRLST_NODE, attrname, tmp); intervalValue = strtoul(tmp, &end, 0) - strtoul(prev, &end, 0); if(intervalValue > 0) p->adslAturChanIntervalReceivedBlks = intervalValue; else p->adslAturChanIntervalReceivedBlks = 0; p->adslAturChanIntervalValidData = 1; } else p->adslAturChanIntervalValidData = 0; if (i == (numOfInterval-1)) p->next=NULL; else { p->next = (p+1); p++; } } p->next = NULL; }
void setup_udp_timeout(int connflag) { unsigned int v[10]; const char *p; char buf[70]; if (connflag // #ifdef RTCONFIG_WIRELESSREPEATER // && nvram_get_int("sw_mode")!=SW_MODE_REPEATER // #endif ) { tcapi_get("SysInfo_Entry", "ct_udp_timeout", buf); p = buf; // p = nvram_safe_get("ct_udp_timeout"); if (sscanf(p, "%u%u", &v[0], &v[1]) == 2) { write_udp_timeout(NULL, v[0]); write_udp_timeout("stream", v[1]); } else { v[0] = read_udp_timeout(NULL); v[1] = read_udp_timeout("stream"); sprintf(buf, "%u %u", v[0], v[1]); // nvram_set("ct_udp_timeout", buf); tcapi_set("SysInfo_Entry", "ct_udp_timeout", buf); } } else { write_udp_timeout(NULL, 1); write_udp_timeout("stream", 6); } }
//recommended buf size is 128 or 256 bytes. If your attribute is a rule list, 2048 is recommended. char *tcapi_get_string(char* node, char* attr, char* buf) { if(!node || !attr || !buf) return NULL; if(tcapi_get(node, attr, buf)) return NULL; return buf; }
void add_custom(int unit, char *p[]) { char node[MAXLEN_NODE_NAME]; char custom[MAXLEN_TCAPI_MSG] = {0}; char *param = NULL; char *final_custom = NULL; int i = 0, size = 0; if(!p[0]) return; while(p[i]) { size += strlen(p[i]) + 1; i++; } param = (char*)calloc(size, sizeof(char)); if(!param) return; i = 0; while(p[i]) { if(*param) strcat(param, " "); strcat(param, p[i]); i++; } snprintf(node, sizeof(node), "OpenVPN_Entry%d", unit + CLIENT_IF_START); tcapi_get(node, "custom", custom); if(strlen(custom)) { if(strlen(custom) + strlen(param) + 1 > MAXLEN_TCAPI_MSG) { logmessage ("OVPN", "Too many custom configuration"); free(param); return; } final_custom = calloc(strlen(custom) + strlen(param) + 2, sizeof(char)); if(final_custom) { if(*custom) { strcat(final_custom, custom); strcat(final_custom, "\n"); } strcat(final_custom, param); tcapi_set(node, "custom", final_custom); free(final_custom); } } else tcapi_set(node, "custom", param); free(param); }
int tcapi_get_int(char* node, char* attr) { char buf[16] = {0}; if(!node || !attr) return 0; if(tcapi_get(node, attr, buf)) return 0; else return atoi(buf); }
/* * Get and merge to list for UI. e.g. <1>aa>bb>cc>...<2>dd>ee>ff>...<3 * @param base_node base name of tcapi node * @param base_attr base name of tcapi attribute * @param list_type 0: merge number to base_node and then get base_attr * e.g. get base_attr in XXX_Entry0 node, base_attr in XXX_Entry1 ... * and then merge to the list_buf * 1: merge number to base_attr and get data from base_node * e.g. get base_attr, base_attr1, base_attr2, ... from base_node * and then merge to the list_buf * list_num total number of list to get * list_value result * len size of list_value * @return 0: succsess * -1: fail */ int _tcapi_get_list(char* base_node, char* base_attr , int list_type, int list_num , char* list_value, size_t len) { char node[MAXLEN_NODE_NAME]; char attr[MAXLEN_ATTR_NAME]; char value[MAXLEN_TCAPI_MSG]; int i; int ret = -1; memset(list_value, 0, len); if(list_type == TCAPI_LIST_TYPE_ATTR) //fixed node, varied attr strncpy(node, base_node, MAXLEN_NODE_NAME-1); else //varied node, fixed attr strncpy(attr, base_attr, MAXLEN_ATTR_NAME-1); for(i = 0; i < list_num; i++) { //update node/attr if(list_type == TCAPI_LIST_TYPE_ATTR) { if(i) snprintf(attr, sizeof(attr), "%s%d", base_attr, i); else snprintf(attr, sizeof(attr), "%s", base_attr); } else { snprintf(node, sizeof(node), "%s%d", base_node, i); } memset(value, 0, sizeof(value)); ret = tcapi_get(node, attr, value); switch(ret) { case TCAPI_PROCESS_OK: //_dprintf("get %s %s=%s\n", node, attr, value); if( (len - strlen(list_value) -1) > strlen(value) ) strcat(list_value, value); else return -1; break; case TCAPI_NONE_NODE: case TCAPI_NONE_ATTR: default: if(i) return 0; else return -1; } } //_dprintf("finally get %s\n", list_value); return 0; }
int islangChanged(void) { char str_type[4] = {0}; int nIndex = 0; tcapi_get("LanguageSwitch_Entry", "Type", str_type); if (strlen(str_type)) nIndex = atoi(str_type); if(nIndex == 0) { memset(str_type, 0, sizeof(str_type)); tcapi_get("WebCurSet_Entry", "detected_lang_type", str_type); if (strlen(str_type)) nIndex = atoi(str_type); } //tcdbg_printf("\r\n*** islangChanged - atoi(str_type): [%d]\n", atoi(str_type)); if (nIndex != init_flag) return 1; else return 0; }
/* * Fill out the ADSL adslAturChanTable */ void adslMibHelper_filladslAturChanTable(pADSL_MIB_ADSLATURCHANTABLE pTable) { pADSL_MIB_ADSLATURCHANTABLE p = pTable; char tmp[32] = {0}; char *end; p->pTableBeginning = pTable; p->ifIndex = getAdslIfIndex(); /*Init the table value*/ p->adslAturChanInterleaveDelay = 0; p->adslAturChanCurrTxRate = 0; p->adslAturChanPrevTxRate = 0; p->adslAturChanCrcBlockLength= 0; tcapi_get(INFOADSL_NODE, ADSL_STATUS_ATTR, tmp); if(0 == strcmp(tmp, ADSL_STATUS_UP)) { memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOADSL_NODE, ATUR_CHAN_ITL_DELAY, tmp); p->adslAturChanInterleaveDelay = strtoul(tmp, &end, 0); memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOADSL_NODE, ATUR_CHAN_PREV_TXRATE, tmp); p->adslAturChanPrevTxRate = strtoul(tmp, &end, 0); memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOADSL_NODE, ATUR_CHAN_CURR_TXRATE, tmp); p->adslAturChanCurrTxRate = strtoul(tmp, &end, 0); memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOADSL_NODE, ATUR_CHAN_CRC_BLK_LEN, tmp); p->adslAturChanCrcBlockLength = strtoul(tmp, &end, 0); } p->next = NULL; }
void write_chap_secret(char *file) { FILE *fp; char nv[MAXLEN_TCAPI_MSG], *nvp, *b; char *username, *passwd; char namebuf[256], passwdbuf[256]; int index = 1; char listname[32] = {0}; fp=fopen(file, "w"); if (fp==NULL) return; if( tcapi_get(VPN_DATA, "pptpd_clientlist", nv) == TCAPI_PROCESS_OK) { nvp = nv; while ((b = strsep(&nvp, "<")) != NULL) { if((vstrsep(b, ">", &username, &passwd)!=2)) continue; if(strlen(username)==0||strlen(passwd)==0) continue; fprintf(fp, "%s * %s *\n", pptp_encode(username, namebuf), pptp_encode(passwd, passwdbuf)); } } for(index = 1; index < 16; index++) { memset(nv, 0, sizeof(nv)); sprintf(listname, "pptpd_clientlist%d", index); if( tcapi_get(VPN_DATA, listname, nv) == TCAPI_PROCESS_OK) { nvp = nv; while ((b = strsep(&nvp, "<")) != NULL) { if((vstrsep(b, ">", &username, &passwd)!=2)) continue; if(strlen(username)==0||strlen(passwd)==0) continue; fprintf(fp, "%s * %s *\n", pptp_encode(username, namebuf), pptp_encode(passwd, passwdbuf)); } } } fclose(fp); }
int tcapi_match(char* node, char* attr, char* value) { char buf[MAXLEN_TCAPI_MSG] = {0}; if(!node || !attr || !value) return 0; if(tcapi_get(node, attr, buf)) return 0; else { if(strcmp(buf, value)) return 0; else return 1; } }
void restart_lfp() { char v[32]; char tmp[32]; tcapi_get("Lan_Entry0", "IP", tmp); // if(nvram_get_int("lfp_disable")==0) { if(tcapi_get_int("GUITemp_Entry1", "lfp_disable")==0) { // sprintf(v, "%x", inet_addr(nvram_safe_get("lan_ipaddr"))); sprintf(v, "%x", inet_addr(tmp)); f_write_string("/proc/net/lfpctrl", v, 0, 0); } else { f_write_string("/proc/net/lfpctrl", "", 0, 0); } }
void setup_ct_timeout(int connflag) { unsigned int v[10]; const char *p; char buf[70]; int i; if (connflag // #ifdef RTCONFIG_WIRELESSREPEATER // && nvram_get_int("sw_mode")!=SW_MODE_REPEATER // #endif ) { tcapi_get("SysInfo_Entry", "ct_udp_timeout", buf); p = buf; // p = nvram_safe_get("ct_timeout"); if (sscanf(p, "%u%u", &v[0], &v[1]) == 2) { // write_ct_timeout("generic", NULL, v[0]); write_ct_timeout("icmp", NULL, v[1]); } else { v[0] = read_ct_timeout("generic", NULL); v[1] = read_ct_timeout("icmp", NULL); sprintf(buf, "%u %u", v[0], v[1]); // nvram_set("ct_timeout", buf); tcapi_set("SysInfo_Entry", "ct_udp_timeout", buf); } } else { for (i = 0; i < 3; i++) { if (scan_icmp_unreplied_conntrack() > 0) { // write_ct_timeout("generic", NULL, 0); write_ct_timeout("icmp", NULL, 0); sleep(2); } } } }
int get_model(void) { char ProductName[32] = {0}; tcapi_get("SysInfo_Entry", "ProductName", ProductName); if(!strcmp(ProductName, "DSL-N16U")) return MODEL_DSLN16U; else if(!strcmp(ProductName, "DSL-N66U")) return MODEL_DSLN66U; else if(!strcmp(ProductName, "DSL-N55U-C1")) return MODEL_DSLN55UC1; else if(!strcmp(ProductName, "DSL-N55U-D1")) return MODEL_DSLN55UD1; else if(!strcmp(ProductName, "DSL-N10-C1")) return MODEL_DSLN10C1; else if(!strcmp(ProductName, "DSL-N10P-C1")) return MODEL_DSLN10PC1; else if(!strcmp(ProductName, "DSL-N12E-C1")) return MODEL_DSLN12EC1; else if(!strcmp(ProductName, "DSL-N10-D1")) return MODEL_DSLN10D1; else if(!strcmp(ProductName, "DSL-N12U-C1")) return MODEL_DSLN12UC1; else if(!strcmp(ProductName, "DSL-N12U-D1")) return MODEL_DSLN12UD1; else if(!strcmp(ProductName, "DSL-N14U")) return MODEL_DSLN14U; else if(!strcmp(ProductName, "DSL-N14U-B1")) return MODEL_DSLN14UB1; else if(!strcmp(ProductName, "DSL-AC56U")) return MODEL_DSLAC56U; else if(!strcmp(ProductName, "DSL-N17U")) return MODEL_DSLN17U; else if(!strcmp(ProductName, "DSL-AC52U")) return MODEL_DSLAC52U; else if(!strcmp(ProductName, "DSL-N16")) return MODEL_DSLN16; else if(!strcmp(ProductName, "DSL-AC55U")) return MODEL_DSLAC55U; else return MODEL_UNKNOWN; }
void main(int argc, char *argv[]) { int sockfd , clisockfd; unsigned int clilen; int childpid; struct sockaddr_in serv_addr,cli_addr; int err_select;//JY1113 char value[32] = {0}; #ifdef LPR_with_ASUS//JY1112 int LPRflag = 0; fd_set rfds, afds; int nfds; int sockfd_ASUS; unsigned int clilen_ASUS; int childpid_ASUS; struct sockaddr_in serv_addr_ASUS,cli_addr_ASUS; #endif #ifdef Raw_Printing_with_ASUS //Lisa int netfd, fd, clientlen, one = 1; struct sockaddr_in netaddr, client; #endif //Initial the server the not busy lptstatus.busy = FALSE; sigset_t sigs_to_catch; sigemptyset(&sigs_to_catch); sigaddset(&sigs_to_catch, SIGCLD); sigaddset(&sigs_to_catch, SIGINT); sigaddset(&sigs_to_catch, SIGQUIT); sigaddset(&sigs_to_catch, SIGKILL); sigaddset(&sigs_to_catch, SIGUSR2); sigprocmask(SIG_UNBLOCK, &sigs_to_catch, NULL); //Setup the signal handler signal(SIGCLD, sig_child); signal(SIGINT, sig_cleanup); signal(SIGQUIT, sig_cleanup); signal(SIGKILL, sig_cleanup); signal(SIGUSR2, sig_remove);//JY1110 if((sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0 ) { //perror("can't open stream socket:"); exit(0); } bzero((char *)&serv_addr , sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_port = htons(PNT_SVR_PORT_LPR); if(bind(sockfd,(struct sockaddr *)&serv_addr , sizeof(serv_addr)) < 0 ) { //perror("can't bind:"); exit(0); } /*JY1111*/ int windowsize=2920; setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (char *)&windowsize, sizeof(windowsize)); int no_delay=1; setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &no_delay, sizeof(no_delay)); // by Jiahao. 20080808. #if 1 int currentpid=getpid(); FILE *pidfileread; if((pidfileread=fopen("/var/run/lpdparent.pid", "r")) == NULL) { pidfileread=fopen("/var/run/lpdparent.pid", "w"); fprintf(pidfileread, "%d", currentpid); fclose(pidfileread); } else{ //printf("another lpd daemon exists!!\n"); fclose(pidfileread); exit(0); } #endif listen(sockfd , 15); #ifdef Raw_Printing_with_ASUS //Lisa if ((netfd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) < 0) { // syslog(LOGOPTS, "socket: %m\n"); exit(1); } if (setsockopt(netfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) { // syslog(LOGOPTS, "setsocketopt: %m\n"); exit(1); } netaddr.sin_port = htons(BASEPORT); netaddr.sin_addr.s_addr = htonl(INADDR_ANY); memset(netaddr.sin_zero, 0, sizeof(netaddr.sin_zero)); if (bind(netfd, (struct sockaddr*) &netaddr, sizeof(netaddr)) < 0) { //syslog(LOGOPTS, "bind: %m\n"); exit(1); } if (listen(netfd, 5) < 0) { //syslog(LOGOPTS, "listen: %m\n"); exit(1); } //clientlen = sizeof(client); //memset(&client, 0, sizeof(client)); #endif #ifdef LPR_with_ASUS//JY1112 if((sockfd_ASUS = socket(AF_INET,SOCK_STREAM,0)) < 0 ) { //perror("can't open stream socket:"); exit(0); } bzero((char *)&serv_addr_ASUS , sizeof(serv_addr_ASUS)); serv_addr_ASUS.sin_family = AF_INET; serv_addr_ASUS.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr_ASUS.sin_port = htons(PNT_SVR_PORT_ASUS); if(bind(sockfd_ASUS,(struct sockaddr *)&serv_addr_ASUS , sizeof(serv_addr_ASUS)) < 0 ) { //perror("can't bind:"); exit(0); } setsockopt(sockfd_ASUS, SOL_SOCKET, SO_RCVBUF, (char *)&windowsize, sizeof(windowsize)); listen(sockfd_ASUS , 15); /*set the fds*/ nfds=MAX(sockfd, sockfd_ASUS); FD_ZERO(&afds); #endif while(TRUE) { //if (busy) syslog(LOG_NOTICE, "busying %d %d\n", lptstatus.busy, busy); bin_sem_wait(); // by Jiahao for U2EC. 20080808. tcapi_get("USB_Entry", "MFP_busy", value); if(lptstatus.busy==FALSE && strcmp(value, "2")) // if (lptstatus.busy==FALSE && nvram_invmatch("MFP_busy", "2")) { busy=FALSE; // nvram_set("MFP_busy", "0"); tcapi_set("USB_Entry", "MFP_busy", "0"); // nvram_set("u2ec_busyip", ""); tcapi_set("USB_Entry", "u2ec_busyip", ""); } bin_sem_post(); #ifdef Raw_Printing_with_ASUS //Lisa FD_SET(netfd, &afds); #endif #ifdef LPR_with_ASUS//JY1112 FD_SET(sockfd, &afds); FD_SET(sockfd_ASUS, &afds); memcpy(&rfds, &afds, sizeof(rfds)); if((err_select=select(nfds+1, &rfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0 )) < 0) { //JY1120 printf("select error on sockfd: error=%d\n", errno); /**/ // printf("sockfd_FD_ISSET=%d\n", FD_ISSET(sockfd, &rfds)); //JY1120 printf("sockfd_ASUS FD_ISSET=%d\n", FD_ISSET(sockfd_ASUS, &rfds)); /**/ // if(errno != 4)//JY1113: delete //syslog(LOG_NOTICE, "select error %d\n", err_select); continue; } #endif clilen = sizeof(cli_addr); if(FD_ISSET(sockfd_ASUS, &rfds)) { LPRflag = 0; clisockfd = accept(sockfd_ASUS,(struct sockaddr *)&cli_addr, &clilen); } #ifdef LPR_with_ASUS//JY1112 else if(FD_ISSET(sockfd, &rfds)) { LPRflag = 1; clisockfd = accept(sockfd,(struct sockaddr *)&cli_addr, &clilen); } #endif #ifdef Raw_Printing_with_ASUS //Lisa // else if(FD_ISSET(netfd, &rfds) && busy==FALSE) else if(FD_ISSET(netfd, &rfds)) { bin_sem_wait(); // by Jiahao for U2EC. 20080808. tcapi_get("USB_Entry", "MFP_busy", value); if( !strcmp(value, "0") ) // if (nvram_match("MFP_busy", "0")) { bin_sem_post(); LPRflag = 2; clisockfd = accept(netfd, (struct sockaddr*) &cli_addr, &clilen); } else { bin_sem_post(); sleep(2); continue; } } #endif else { //syslog(LOG_NOTICE, "No select\n"); sleep(2); continue; } strcpy(clientaddr , inet_ntoa(cli_addr.sin_addr)); if(clisockfd < 0) { //syslog(LOG_NOTICE, "LPD error: No clisockfd %d\n", LPRflag); continue; } bin_sem_wait(); // if (busy!=FALSE) /* 2004/09/10 by Joey, process nack in parent for LPR and Remote Prot */ tcapi_get("USB_Entry", "MFP_busy", value); if(strcmp(value, "0")) // if (nvram_invmatch("MFP_busy", "0")) // by Jiahao for U2EC. 20080808. { bin_sem_post(); //syslog(LOG_NOTICE, "Printing others 1 %d %d\n", LPRflag, clisockfd); if (LPRflag==0) processReq(clisockfd); else if (LPRflag==1) processReq_LPR(clisockfd, 0); //syslog(LOG_NOTICE, "Printing others %d %d\n", LPRflag, clisockfd); close(clisockfd); // For Raw printing, don't resonse to client while busy sleep(5); continue; } // nvram_set("MFP_busy", "1"); tcapi_set("USB_Entry", "MFP_busy", "1"); // if (nvram_match("lan_ipaddr_t", "")) // nvram_set("u2ec_busyip", nvram_safe_get("lan_ipaddr")); // else // nvram_set("u2ec_busyip", nvram_safe_get("lan_ipaddr_t")); tcapi_get("Lan_Entry0", "IP", value); tcapi_set("USB_Entry", "u2ec_busyip", value); bin_sem_post(); if( (childpid = fork() ) < 0) { } else if(childpid == 0) { //syslog(LOG_NOTICE, "Printing %d\n", LPRflag); if(LPRflag==0) processReq(clisockfd); #ifdef LPR_with_ASUS//JY1114 else if(LPRflag==1) processReq_LPR(clisockfd, 1); #endif #ifdef Raw_Printing_with_ASUS //Lisa else if(LPRflag == 2) processReq_Raw(clisockfd); #endif close(sockfd); close(sockfd_ASUS); close(netfd); exit(0); } //syslog(0, "Printing Process %d %d %d\n", busy, lptstatus.busy, childpid); //parents process goes on here //remark PRINT("fork -- childpid %d\n",childpid); if(lptstatus.busy == FALSE) { lptstatus.busy = TRUE; // busy = TRUE; // remarked by Jiahao for U2EC. 20080808. strcpy(lptstatus.addr , inet_ntoa(cli_addr.sin_addr)); lptstatus.pid = childpid; } close(clisockfd); } }
void setup_conntrack(void) { unsigned int v[10]; char p[128] = {0}; char buf[70]; int i; char *pch; // p = nvram_safe_get("ct_tcp_timeout"); tcapi_get("SysInfo_Entry", "ct_tcp_timeout", p); if (sscanf(p, "%u%u%u%u%u%u%u%u%u%u", &v[0], &v[1], &v[2], &v[3], &v[4], &v[5], &v[6], &v[7], &v[8], &v[9]) == 10) { // lightly verify write_tcp_timeout("established", v[1]); write_tcp_timeout("syn_sent", v[2]); write_tcp_timeout("syn_recv", v[3]); write_tcp_timeout("fin_wait", v[4]); write_tcp_timeout("time_wait", v[5]); write_tcp_timeout("close", v[6]); write_tcp_timeout("close_wait", v[7]); write_tcp_timeout("last_ack", v[8]); } else { v[1] = read_tcp_timeout("established"); v[2] = read_tcp_timeout("syn_sent"); v[3] = read_tcp_timeout("syn_recv"); v[4] = read_tcp_timeout("fin_wait"); v[5] = read_tcp_timeout("time_wait"); v[6] = read_tcp_timeout("close"); v[7] = read_tcp_timeout("close_wait"); v[8] = read_tcp_timeout("last_ack"); sprintf(buf, "0 %u %u %u %u %u %u %u %u 0", v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8]); // nvram_set("ct_tcp_timeout", buf); tcapi_set("SysInfo_Entry", "ct_tcp_timeout", buf); } setup_udp_timeout(FALSE); // p = nvram_safe_get("ct_timeout"); tcapi_get("SysInfo_Entry", "ct_timeout", p); if (sscanf(p, "%u%u", &v[0], &v[1]) == 2) { // write_ct_timeout("generic", NULL, v[0]); write_ct_timeout("icmp", NULL, v[1]); } else { v[0] = read_ct_timeout("generic", NULL); v[1] = read_ct_timeout("icmp", NULL); sprintf(buf, "%u %u", v[0], v[1]); // nvram_set("ct_timeout", buf); tcapi_set("SysInfo_Entry", "ct_timeout", buf); } #ifdef LINUX26 // p = nvram_safe_get("ct_hashsize"); tcapi_get("SysInfo_Entry", "ct_hashsize", p); i = atoi(p); if (i >= 127) { f_write_string("/sys/module/nf_conntrack/parameters/hashsize", p, 0, 0); } else if (f_read_string("/sys/module/nf_conntrack/parameters/hashsize", buf, sizeof(buf)) > 0) { if (atoi(buf) > 0) {//nvram_set("ct_hashsize", buf); pch = strchr(buf, '\n'); if(pch != NULL) memset(pch, 0, 1); tcapi_set("SysInfo_Entry", "ct_hashsize", buf); } } #endif // p = nvram_safe_get("ct_max"); tcapi_get("SysInfo_Entry", "ct_max", p); i = atoi(p); if (i >= 128) { f_write_string("/proc/sys/net/ipv4/netfilter/ip_conntrack_max", p, 0, 0); } else if (f_read_string("/proc/sys/net/ipv4/netfilter/ip_conntrack_max", buf, sizeof(buf)) > 0) { if (atoi(buf) > 0) {//nvram_set("ct_max", buf); pch = strchr(buf, '\n'); if(pch != NULL) memset(pch, 0, 1); tcapi_set("SysInfo_Entry", "ct_max", buf); } } //if (!nvram_match("nf_rtsp", "0")) { // ct_modprobe("rtsp"); //} //else { // ct_modprobe_r("rtsp"); //} // if (!nvram_match("nf_h323", "0")) { // ct_modprobe("h323"); // } // else { // ct_modprobe_r("h323"); // } // #ifdef LINUX26 // if (!nvram_match("nf_sip", "0")) { // ct_modprobe("sip"); // } // else { // ct_modprobe_r("sip"); // } // #endif // !!TB - FTP Server // #ifdef RTCONFIG_FTP // i = nvram_get_int("ftp_port"); // if (nvram_match("ftp_enable", "1") && (i > 0) && (i != 21)) // { // char ports[32]; // sprintf(ports, "ports=21,%d", i); // ct_modprobe("ftp", ports); // } // else // #endif // if (!nvram_match("nf_ftp", "0") // #ifdef RTCONFIG_FTP // || nvram_match("ftp_enable", "1") // !!TB - FTP Server // #endif // ) { // ct_modprobe("ftp"); // } // else { // ct_modprobe_r("ftp"); // } // if (!nvram_match("nf_pptp", "0")) { // ct_modprobe("proto_gre"); // ct_modprobe("pptp"); // } // else { // ct_modprobe_r("pptp"); // ct_modprobe_r("proto_gre"); // } }
char *add_nvram_contents(char *url,char *folder) { DEBUG("add_nvram_contents start\n"); char *nv; int nv_len; char *new_nv; char *nvp; nvp = my_malloc(strlen(url) + strlen(folder) + 2); //2014.10.20 by sherry malloc申请内存是否成功 // if(nvp==NULL) // return NULL; sprintf(nvp, "%s>%s", url, folder); DEBUG("add_nvram_contents nvp = %s\n",nvp); #ifdef NVRAM_ #ifdef USE_TCAPI char tmp[MAXLEN_TCAPI_MSG] = {0}; tcapi_get(AICLOUD, "usb_tokenfile", tmp); nv = my_malloc(strlen(tmp) + 1); //2014.10.20 by sherry malloc申请内存是否成功 // if(nv==NULL) // return NULL; sprintf(nv, "%s", tmp); //p = nv; #else nv = strdup(nvram_safe_get("usb_tokenfile")); #endif #else FILE *fp; fp = fopen("/opt/etc/usb_tokenfile", "r"); if (fp == NULL) { nv = my_malloc(2); //2014.10.20 by sherry malloc申请内存是否成功 // if(nv==NULL) // return NULL; sprintf(nv, ""); } else { fseek( fp , 0 , SEEK_END ); int file_size; file_size = ftell( fp ); fseek(fp , 0 , SEEK_SET); nv = my_malloc(file_size + 2); //2014.10.20 by sherry malloc申请内存是否成功 // if(nv==NULL) // return NULL; fscanf(fp, "%[^\n]%*c", nv); fclose(fp); } #endif DEBUG("add_nvram_contents() - nv = %s\n", nv); nv_len = strlen(nv); if(nv_len) { new_nv = my_malloc(strlen(nv) + strlen(nvp) + 2); //2014.10.20 by sherry malloc申请内存是否成功 // if(new_nv==NULL) // return NULL; sprintf(new_nv, "%s<%s", nv, nvp); } else { new_nv = my_malloc(strlen(nvp) + 1); //2014.10.20 by sherry malloc申请内存是否成功 // if(new_nv==NULL) // return NULL; sprintf(new_nv, "%s", nvp); } free(nvp); free(nv); DEBUG("add_nvram_contents end\n"); return new_nv; }
int read_header(request * req) { int bytes, buf_bytes_left; char *check, *buffer; char *pstr; char str_lang[6]; char str_type[4] = {0}; int nIndex = 1; char ttc[16] = {0}; check = req->client_stream + req->parse_pos; buffer = req->client_stream; bytes = req->client_stream_pos; #ifdef VERY_FASCIST_LOGGING if (check < (buffer + bytes)) { buffer[bytes] = '\0'; log_error_time(); fprintf(stderr, "1) %s:%d - Parsing headers (\"%s\")\n", __FILE__, __LINE__, check); } #endif tcapi_get("SysInfo_Entry", "TerritoryCode", ttc); /* Paul add 2013/3/7, for retrieve Language type from HTTP header */ tcapi_get("LanguageSwitch_Entry", "Type", str_type); if(strlen(str_type)) nIndex = atoi(str_type); if(nIndex == 0) /* Language never been set before, start checking */ { tcapi_get("WebCurSet_Entry", "detected_lang_type", str_type); if(strlen(str_type)) nIndex = atoi(str_type); if(nIndex == 0) { // Language never been detect before, start checking memset(str_lang, 0, sizeof(str_lang)); if(pstr = strstr(check,"Accept-Language:")) { strncpy (str_lang, &check[pstr-check+17], 6); str_lang[5] = '\0'; int i, len = strlen(str_lang); for(i=0; i<len; ++i) { if(isupper(str_lang[i])){ str_lang[i] = tolower(str_lang[i]); } } //choose proper language type sprintf(str_type, "%d", getLangType(ttc, str_lang) ); tcapi_set("WebCurSet_Entry", "detected_lang_type", str_type); initandparserfile(); } } } while (check < (buffer + bytes)) { switch (req->status) { case READ_HEADER: if (*check == '\r') { req->status = ONE_CR; req->header_end = check; } else if (*check == '\n') { req->status = ONE_LF; req->header_end = check; } break; case ONE_CR: if (*check == '\n') req->status = ONE_LF; else if (*check != '\r') req->status = READ_HEADER; break; case ONE_LF: /* if here, we've found the end (for sure) of a header */ if (*check == '\r') /* could be end o headers */ req->status = TWO_CR; else if (*check == '\n') req->status = BODY_READ; else req->status = READ_HEADER; break; case TWO_CR: if (*check == '\n') req->status = BODY_READ; else if (*check != '\r') req->status = READ_HEADER; break; default: break; } #if 0 #ifdef VERY_FASCIST_LOGGING log_error_time(); fprintf(stderr, "status, check: %d, %d\n", req->status, *check); #endif #endif req->parse_pos++; /* update parse position */ check++; if (req->status == ONE_LF) { *req->header_end = '\0'; /* terminate string that begins at req->header_line */ if (req->logline) { if (process_option_line(req) == 0) { return 0; } } else { if (process_logline(req) == 0) return 0; if (req->simple) return process_header_end(req); } /* set header_line to point to beginning of new header */ req->header_line = check; } else if (req->status == BODY_READ) { #ifdef VERY_FASCIST_LOGGING int retval; log_error_time(); fprintf(stderr, "%s:%d -- got to body read.\n", __FILE__, __LINE__); retval = process_header_end(req); #else int retval = process_header_end(req); #endif /* process_header_end inits non-POST cgi's */ if (retval && req->method == M_POST) { /* for body_{read,write}, set header_line to start of data, and header_end to end of data */ req->header_line = check; req->header_end = req->client_stream + req->client_stream_pos; req->status = BODY_WRITE; /* so write it */ /* have to write first, or read will be confused * because of the special case where the * filesize is less than we have already read. */ /* As quoted from RFC1945: A valid Content-Length is required on all HTTP/1.0 POST requests. An HTTP/1.0 server should respond with a 400 (bad request) message if it cannot determine the length of the request message's content. */ if (req->content_length) { int content_length; content_length = boa_atoi(req->content_length); #if 0 //Content-Length is required but don't limit to larger then zero. Sam, 2013/7/3 /* Is a content-length of 0 legal? */ if (content_length <= 0) { log_error_time(); fprintf(stderr, "Invalid Content-Length [%s] on POST!\n", req->content_length); send_r_bad_request(req); return 0; } #endif if (single_post_limit && content_length > single_post_limit) { log_error_time(); fprintf(stderr, "Content-Length [%d] > SinglePostLimit [%d] on POST!\n", content_length, single_post_limit); send_r_bad_request(req); return 0; } req->filesize = content_length; req->filepos = 0; if (req->header_end - req->header_line > req->filesize) { req->header_end = req->header_line + req->filesize; } } else { log_error_time(); fprintf(stderr, "Unknown Content-Length POST!\n"); send_r_bad_request(req); return 0; } } /* either process_header_end failed or req->method != POST */ return retval; /* 0 - close it done, 1 - keep on ready */ } /* req->status == BODY_READ */ } /* done processing available buffer */ #ifdef VERY_FASCIST_LOGGING log_error_time(); fprintf(stderr, "%s:%d - Done processing buffer. Status: %d\n", __FILE__, __LINE__, req->status); #endif if (req->status < BODY_READ) { /* only reached if request is split across more than one packet */ buf_bytes_left = CLIENT_STREAM_SIZE - req->client_stream_pos; if (buf_bytes_left < 1) { log_error_time(); fputs("buffer overrun - read.c, read_header - closing\n", stderr); req->status = DEAD; return 0; } #if defined(TCSUPPORT_WEBSERVER_SSL) if(req->ssl == NULL) #endif { bytes = read(req->fd, buffer + req->client_stream_pos, buf_bytes_left); } #if defined(TCSUPPORT_WEBSERVER_SSL) else{ bytes = boa_sslRead(req->ssl, buffer + req->client_stream_pos, buf_bytes_left); } #endif if (bytes < 0) { if (errno == EINTR) return 1; if (errno == EAGAIN || errno == EWOULDBLOCK) /* request blocked */ return -1; /* else if (errno == EBADF || errno == EPIPE) { req->status = DEAD; return 0; */ #if 0 //lee 9-25 log_error_doc(req); perror("header read"); /* don't need to save errno because log_error_doc does */ #endif return 0; } else if (bytes == 0) { /* log_error_time(); fputs("unexpected end of headers\n", stderr); */ return 0; } /* bytes is positive */ req->client_stream_pos += bytes; #ifdef FASCIST_LOGGING1 log_error_time(); req->client_stream[req->client_stream_pos] = '\0'; fprintf(stderr, "%s:%d -- We read %d bytes: \"%s\"\n", __FILE__, __LINE__, bytes, #ifdef VERY_FASCIST_LOGGING2 req->client_stream + req->client_stream_pos - bytes); #else ""); #endif #endif return 1; }
/* Paul modify 2013/2/7 */ int initandparserfile(void) { //FILE *fp = NULL; char *pk = NULL; char str_path[PATH_LENGTH] = {0}; char stream[MAX_STREAM] = {0}; char str_key[MAX_KEY] = {0}; char str_type[4] = {0}; int nIndex = 0; uint offset = 0; HASH s_hash; SParser s_parse_tmp; //Andy Chiu, 2015/03/03. retry for cfg_manager restart scoket issue. int res = 0, i; for(i = 0; i < 5; ++i) { res = tcapi_get("LanguageSwitch_Entry", "Type", str_type); if(!res && strlen(str_type) > 0 ) break; tcdbg_printf("[%s, %d]get lang failed!\n", __FUNCTION__, __LINE__); sleep(1); } if (strlen(str_type)) nIndex = atoi(str_type); if(nIndex == 0) { for(i = 0; i < 5; ++i) { memset(str_type, 0, sizeof(str_type)); res = tcapi_get("WebCurSet_Entry", "detected_lang_type", str_type); if(!res && strlen(str_type) > 0 ) break; tcdbg_printf("[%s, %d]get lang failed!\n", __FUNCTION__, __LINE__); sleep(1); } if (strlen(str_type)) nIndex = atoi(str_type); } init_flag = nIndex; closefp();//close file pointer at first if(nIndex == 1) //English sprintf(str_path, STRING_PATH, "EN"); else if(nIndex == 2) //Brazil sprintf(str_path, STRING_PATH, "BR"); else if(nIndex == 3) //Simplified Chinese sprintf(str_path, STRING_PATH, "CN"); else if(nIndex == 4) //Cesky sprintf(str_path, STRING_PATH, "CZ"); else if(nIndex == 5) //Dansk sprintf(str_path, STRING_PATH, "DA"); else if(nIndex == 6) //Deutsch sprintf(str_path, STRING_PATH, "DE"); else if(nIndex == 7) //Espanol sprintf(str_path, STRING_PATH, "ES"); else if(nIndex == 8) //Finsk sprintf(str_path, STRING_PATH, "FI"); else if(nIndex == 9) //Francais sprintf(str_path, STRING_PATH, "FR"); else if(nIndex == 10) //Italiano sprintf(str_path, STRING_PATH, "IT"); else if(nIndex == 11) //Malay sprintf(str_path, STRING_PATH, "MS"); else if(nIndex == 12) //Norsk sprintf(str_path, STRING_PATH, "NO"); else if(nIndex == 13) //Polski sprintf(str_path, STRING_PATH, "PL"); else if(nIndex == 14) //Russian sprintf(str_path, STRING_PATH, "RU"); else if(nIndex == 15) //Svensk sprintf(str_path, STRING_PATH, "SV"); else if(nIndex == 16) //Thai sprintf(str_path, STRING_PATH, "TH"); else if(nIndex == 17) //Turkey sprintf(str_path, STRING_PATH, "TR"); else if(nIndex == 18) //Traditional Chinese sprintf(str_path, STRING_PATH, "TW"); else if(nIndex == 19) //Ukraine sprintf(str_path, STRING_PATH, "UK"); else sprintf(str_path, STRING_PATH, "EN"); fpl=fopen(str_path,"r"); if(fpl == NULL) { tcdbg_printf("\r\n%s:can't open %s\r\n",__FUNCTION__, str_path); return FAILURE; } if (FAILURE == initHashTable(&s_parse_tmp)) { tcdbg_printf("\r\n%s:alloc memory\n", __FUNCTION__); return FAILURE; } ResetHashTable(&s_parse);//free memory at first s_parse = s_parse_tmp; fseek(fpl, 0, SEEK_SET); while(fgets(stream, MAX_STREAM, fpl) != NULL) { int len = strlen(stream); pk = strstr(stream,"="); if ((stream[0] == ';') || (NULL == pk)) { offset += len; continue; } *pk = '\0'; strncpy(str_key, stream, strlen(stream)); s_hash.key = getkey(str_key); s_hash.ioffset = offset; offset += len; strcpy(str_attrname, str_key); insertToHash(&s_parse, s_hash); memset(stream, 0, MAX_STREAM); memset(str_key, 0, MAX_KEY); } //fclose(fp); return SUCCESS; }
static void dhcpExtractOption43(uint8_t *data, int len) { uint8_t *datap = data; int index = 0, paramLen = 0, ret = 0, spSaveFlag = 0, bootstrapFlag = 0; char tempCwmpString[CwmpTempStringMaxLen]; char buf[CwmpTempStringMaxLen]; if(data == NULL){ return; } while (index < len) { switch (datap[index]){ case OPT43_SUBOPT_ACS_URL: #ifdef OPT43_DBG tcdbg_printf("%s: acs url case\n", __FUNCTION__); #endif paramLen = min((CwmpURLMaxLen-1), datap[index+1]); memset(tempCwmpString, 0, CwmpTempStringMaxLen); memcpy(tempCwmpString, &datap[index+2], paramLen); memset(buf, 0, sizeof(buf)); tcapi_get("Cwmp_Entry", "acsUrl", buf); if (0 != strcmp(buf, tempCwmpString)) { tcapi_set("Cwmp_Entry", "acsUrl", (char*)tempCwmpString); spSaveFlag = 1; bootstrapFlag = 1; } break; case OPT43_SUBOPT_PRVCODE: #ifdef OPT43_DBG tcdbg_printf("%s: prv code case.\n", __FUNCTION__); #endif paramLen = min((CwmpPrvCodeMaxLen-1), datap[index+1]); memset(tempCwmpString, 0, CwmpTempStringMaxLen); memcpy(tempCwmpString, &datap[index+2], paramLen); memset(buf, 0, sizeof(buf)); tcapi_get("Cwmp_Entry", "PrvCode", buf); if (0 != strcmp(buf, tempCwmpString)) { tcapi_set("Cwmp_Entry", "PrvCode", (char*)tempCwmpString); spSaveFlag = 1; } break; default: #ifdef OPT43_DBG tcdbg_printf("%s,default case,and datap[index]=%d\n", __FUNCTION__, datap[index]); #endif break; } if (datap[index] == DHCP_PADDING) index++; else if(datap[index] == DHCP_END) break; else index += (datap[index+1] + 2); } #ifdef OPT43_DBG tcdbg_printf("%s spSaveFlag=%d bootstrapFlag=%d\n", __FUNCTION__, spSaveFlag, bootstrapFlag); #endif /* save to flash */ if (spSaveFlag) tcapi_save(); /* send msg to cwmp for signal inform */ if (bootstrapFlag) tcapi_commit("Cwmp_Entry"); return; }
/* * Fill out the ADSL adslAturChanPerfDataTable */ void adslMibHelper_filladslAturChanPerfDataTable (pADSL_MIB_ADSLATURCHANPERFDATATABLE pTable) { pADSL_MIB_ADSLATURCHANPERFDATATABLE p = pTable; char tmp[32] = {0}; char status[8] = {0}; char *end; unsigned long total= 0, qutHourSt = 0, interval = 0; p->pTableBeginning = pTable; p->ifIndex = getAdslIfIndex(); /*Init the table value*/ memcpy((void *)&p->adslAturChanReceivedBlks,"0", 1); p->adslAturChanPerfValidIntervals = 0; p->adslAturChanPerfInvalidIntervals = 0; p->adslAturChanPerfCurr15MinTimeElapsed = 0; memcpy((void *)&p->adslAturChanPerfCurr15MinReceivedBlks,"0", 1); p->adslAturChanPerfCurr1DayTimeElapsed = 0; memcpy((void *)&p->adslAturChanPerfCurr1DayReceivedBlks,"0", 1); p->adslAturChanPerfPrev1DayMoniSecs = 0; memcpy((void *)&p->adslAturChanPerfPrev1DayReceivedBlks,"0", 1); /* 0. get adsl status */ tcapi_get(INFOADSL_NODE, ADSL_STATUS_ATTR, status); /* 1. get total rx blocks */ memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOTOTAL_NODE, TOTAL_ATUR_CHAN_RXBLKS, tmp); total = strtoul(tmp, &end, 0); /* 2. get current interval rx blocks */ memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOSHOW_NODE, ATUR_CHAN_RXBLKS, tmp); interval = strtoul(tmp, &end, 0); //adslAturChanReceivedBlks p->adslAturChanReceivedBlks = total; if(0 == strcmp(status, ADSL_STATUS_UP)) { p->adslAturChanReceivedBlks += interval; } //adslAturChanPerfValidIntervals memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOSHOW_NODE, ATUR_CHAN_PERF_VALID_ITLS, tmp); p->adslAturChanPerfValidIntervals = strtoul(tmp, &end, 0); //ATURChanPerfInValidIntervals memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOSHOW_NODE, ATUR_CHAN_PERF_INVALID_ITLS, tmp); p->adslAturChanPerfInvalidIntervals = strtoul(tmp, &end, 0); //adslAturChanPerfCurr15MinTimeElapsed memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOSHOW_NODE, QUT_HRS_ATUR_CHAN_TIMEELAPSED, tmp); p->adslAturChanPerfCurr15MinTimeElapsed = strtoul(tmp, &end, 0); //adslAturChanPerfCurr1DayTimeElapsed memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOSHOW_NODE, CURDAY_TIMEELAPSED, tmp); p->adslAturChanPerfCurr1DayTimeElapsed = strtoul(tmp, &end, 0); //adslAturChanPerfPrev1DayMoniSecs memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOSHOW_NODE, PREVDAY_ATUR_CHAN_MONISECS, tmp); p->adslAturChanPerfPrev1DayMoniSecs = strtoul(tmp, &end, 0); //adslAturChanPerfCurr15MinReceivedBlks p->adslAturChanPerfCurr15MinReceivedBlks = total; if(0 == strcmp(status, ADSL_STATUS_UP)) { p->adslAturChanPerfCurr15MinReceivedBlks += interval; } memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOQUTHOURST_NODE, QUTHRS_ATUR_CHAN_RXBLKS, tmp); p->adslAturChanPerfCurr15MinReceivedBlks -= strtoul(tmp, &end, 0); //adslAturChanPerfCurr1DayReceivedBlks p->adslAturChanPerfCurr1DayReceivedBlks = total; if(0 == strcmp(status, ADSL_STATUS_UP)) { p->adslAturChanPerfCurr1DayReceivedBlks += interval; } memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOCURDAYST_NODE, CURDAY_ATUR_CHAN_RXBLKS, tmp); p->adslAturChanPerfCurr1DayReceivedBlks -= strtoul(tmp, &end, 0); //adslAturChanPerfPrev1DayReceivedBlks memset(tmp, 0, sizeof(tmp)); tcapi_get(INFOCURDAYST_NODE, PREVDAY_ATUR_CHAN_RXBLKS, tmp); p->adslAturChanPerfPrev1DayReceivedBlks -= strtoul(tmp, &end, 0); p->next = NULL; }
int main(int argc, char *argv[]) { int arp_sockfd, arp_getlen, i; int send_count=0, file_num=0; struct sockaddr_in router_addr, device_addr; char router_ipaddr[17], router_mac[17], buffer[ARP_BUFFER_SIZE]; unsigned char scan_ipaddr[4]; // scan ip FILE *fp_ip, *fp; fd_set rfds; ARP_HEADER * arp_ptr; struct timeval tv1, tv2, arp_timeout; int shm_client_detail_info_id; int ip_dup, mac_dup, real_num; int lock; int ret; int pid, flag; //Andy Chiu, 2015/06/16. Checking the networkmap exist. unsigned short msg_type; #if defined(RTCONFIG_QCA) && defined(RTCONFIG_WIRELESSREPEATER) char *mac; #endif signal(SIGTERM, nwmap_sig_term); //Andy Chiu, 2015/06/12. Add for terminate signal handling loop = 1; //Andy Chiu, 2015/06/16. check otehr networkmap exist. flag = 0; fp = fopen("/var/run/networkmap.pid", "r"); if(fp) { if(fscanf(fp, "%d", &pid) > 0) { sprintf(buffer, "/proc/%d", pid); if(!access(buffer, F_OK)) flag = 1; } fclose(fp); } if(flag) { NMP_DEBUG("[%s, %d]networkmap is already running now.\n", __FUNCTION__, __LINE__); return 0; } fp = fopen("/var/run/networkmap.pid", "w"); if(fp != NULL){ fprintf(fp, "%d", getpid()); fclose(fp); } #ifdef DEBUG eval("rm", "/var/client*"); #endif //Initial client tables lock = file_lock("networkmap"); shm_client_detail_info_id = shmget((key_t)1001, sizeof(CLIENT_DETAIL_INFO_TABLE), 0666|IPC_CREAT); if (shm_client_detail_info_id == -1){ fprintf(stderr,"shmget failed\n"); file_unlock(lock); exit(1); } CLIENT_DETAIL_INFO_TABLE *p_client_detail_info_tab = (P_CLIENT_DETAIL_INFO_TABLE)shmat(shm_client_detail_info_id,(void *) 0,0); //Reset shared memory memset(p_client_detail_info_tab, 0x00, sizeof(CLIENT_DETAIL_INFO_TABLE)); p_client_detail_info_tab->ip_mac_num = 0; p_client_detail_info_tab->detail_info_num = 0; file_unlock(lock); #ifdef NMP_DB nmp_client_list = NULL; if(!load_db(&nmp_client_list) && nmp_client_list) NMP_DEBUG_M("NMP Client:\n%s\n", nmp_client_list); signal(SIGUSR2, reset_db); #endif //Get Router's IP/Mac //Andy Chiu, 2014/10/22. tcapi_get("Info_Ether", "ip", router_ipaddr); tcapi_get("Info_Ether", "mac", router_mac); inet_aton(router_ipaddr, &router_addr.sin_addr); memcpy(my_ipaddr, &router_addr.sin_addr, 4); //Prepare scan networkmap_fullscan = 1; //Andy Chiu, 2014/10/22. if(tcapi_set("ClientList_Common", "scan", "1")) NMP_DEBUG_M("set node(ClientList_Common:scan) failed.\n"); if (argc > 1) { if (strcmp(argv[1], "--bootwait") == 0) { sleep(30); //Andy Chiu, 2014/12/09 if(!access("/var/static_arp_tbl.sh", F_OK)) system("/var/static_arp_tbl.sh"); } } if (strlen(router_mac)!=0) ether_atoe(router_mac, my_hwaddr); signal(SIGUSR1, refresh_sig); //catch UI refresh signal // create UDP socket and bind to "br0" to get ARP packet// arp_sockfd = create_socket(INTERFACE); if(arp_sockfd < 0) perror("create socket ERR:"); else { arp_timeout.tv_sec = 0; arp_timeout.tv_usec = 50000; setsockopt(arp_sockfd, SOL_SOCKET, SO_RCVTIMEO, &arp_timeout, sizeof(arp_timeout));//set receive timeout dst_sockll = src_sockll; //Copy sockaddr info to dst memset(dst_sockll.sll_addr, -1, sizeof(dst_sockll.sll_addr)); // set dmac= FF:FF:FF:FF:FF:FF } while(loop)//main while loop { while(loop) { //full scan and reflush recv buffer fullscan: if(networkmap_fullscan == 1) { //Scan all IP address in the subnetwork if(scan_count == 0) { eval("asusdiscovery"); //find asus device // (re)-start from the begining memset(scan_ipaddr, 0x00, 4); memcpy(scan_ipaddr, &router_addr.sin_addr, 3); arp_timeout.tv_sec = 0; arp_timeout.tv_usec = 50000; setsockopt(arp_sockfd, SOL_SOCKET, SO_RCVTIMEO, &arp_timeout, sizeof(arp_timeout));//set receive timeout NMP_DEBUG("Starting full scan!\n"); //Andy Chiu, 2014/10/22. remove unused flag, "refresh_networkmap". #if 0 if(nvram_match("refresh_networkmap", "1")) //reset client tables { lock = file_lock("networkmap"); memset(p_client_detail_info_tab, 0x00, sizeof(CLIENT_DETAIL_INFO_TABLE)); //p_client_detail_info_tab->detail_info_num = 0; //p_client_detail_info_tab->ip_mac_num = 0; file_unlock(lock); nvram_unset("refresh_networkmap"); } else { int x = 0; for(; x<255; x++) p_client_detail_info_tab->exist[x]=0; } #else memset(p_client_detail_info_tab, 0x00, sizeof(CLIENT_DETAIL_INFO_TABLE)); #endif } scan_count++; scan_ipaddr[3]++; if( scan_count<255 && memcmp(scan_ipaddr, my_ipaddr, 4) ) { sent_arppacket(arp_sockfd, scan_ipaddr); } else if(scan_count==255) { //Scan completed arp_timeout.tv_sec = 2; arp_timeout.tv_usec = 0; //Reset timeout at monitor state for decase cpu loading setsockopt(arp_sockfd, SOL_SOCKET, SO_RCVTIMEO, &arp_timeout, sizeof(arp_timeout));//set receive timeout networkmap_fullscan = 0; //scan_count = 0; //nvram_set("networkmap_fullscan", "0"); if(tcapi_set("ClientList_Common", "scan", "0")) NMP_DEBUG_M("set node(ClientList_Common:scan) failed.\n"); NMP_DEBUG("Finish full scan!\n"); } }// End of full scan memset(buffer, 0, ARP_BUFFER_SIZE); arp_getlen=recvfrom(arp_sockfd, buffer, ARP_BUFFER_SIZE, 0, NULL, NULL); if(arp_getlen == -1) { if( scan_count<255) goto fullscan; else break; } else { arp_ptr = (ARP_HEADER*)(buffer); NMP_DEBUG("*Receive an ARP Packet from: %d.%d.%d.%d to %d.%d.%d.%d:%02X:%02X:%02X:%02X - len:%d\n", (int *)arp_ptr->source_ipaddr[0],(int *)arp_ptr->source_ipaddr[1], (int *)arp_ptr->source_ipaddr[2],(int *)arp_ptr->source_ipaddr[3], (int *)arp_ptr->dest_ipaddr[0],(int *)arp_ptr->dest_ipaddr[1], (int *)arp_ptr->dest_ipaddr[2],(int *)arp_ptr->dest_ipaddr[3], arp_ptr->dest_hwaddr[0],arp_ptr->dest_hwaddr[1], arp_ptr->dest_hwaddr[2],arp_ptr->dest_hwaddr[3], arp_getlen); //Check ARP packet if source ip and router ip at the same network if( !memcmp(my_ipaddr, arp_ptr->source_ipaddr, 3) ) { msg_type = ntohs(arp_ptr->message_type); if( //ARP packet to router ( msg_type == 0x02 && // ARP response memcmp(arp_ptr->dest_ipaddr, my_ipaddr, 4) == 0 && // dest IP memcmp(arp_ptr->dest_hwaddr, my_hwaddr, 6) == 0) // dest MAC || (msg_type == 0x01 && // ARP request memcmp(arp_ptr->dest_ipaddr, my_ipaddr, 4) == 0) // dest IP ){ //NMP_DEBUG(" It's an ARP Response to Router!\n"); NMP_DEBUG("*RCV %d.%d.%d.%d-%02X:%02X:%02X:%02X:%02X:%02X\n", arp_ptr->source_ipaddr[0],arp_ptr->source_ipaddr[1], arp_ptr->source_ipaddr[2],arp_ptr->source_ipaddr[3], arp_ptr->source_hwaddr[0],arp_ptr->source_hwaddr[1], arp_ptr->source_hwaddr[2],arp_ptr->source_hwaddr[3], arp_ptr->source_hwaddr[4],arp_ptr->source_hwaddr[5]); for(i=0; i<p_client_detail_info_tab->ip_mac_num; i++) { ip_dup = memcmp(p_client_detail_info_tab->ip_addr[i], arp_ptr->source_ipaddr, 4); mac_dup = memcmp(p_client_detail_info_tab->mac_addr[i], arp_ptr->source_hwaddr, 6); if((ip_dup == 0) && (mac_dup == 0)) { lock = file_lock("networkmap"); p_client_detail_info_tab->exist[i] = 1; file_unlock(lock); break; } else if((ip_dup != 0) && (mac_dup != 0)) { continue; } else if( (scan_count>=255) && ((ip_dup != 0) && (mac_dup == 0)) ) { NMP_DEBUG("IP changed, update immediately\n"); NMP_DEBUG("*CMP %d.%d.%d.%d-%02X:%02X:%02X:%02X:%02X:%02X\n", p_client_detail_info_tab->ip_addr[i][0],p_client_detail_info_tab->ip_addr[i][1], p_client_detail_info_tab->ip_addr[i][2],p_client_detail_info_tab->ip_addr[i][3], p_client_detail_info_tab->mac_addr[i][0],p_client_detail_info_tab->mac_addr[i][1], p_client_detail_info_tab->mac_addr[i][2],p_client_detail_info_tab->mac_addr[i][3], p_client_detail_info_tab->mac_addr[i][4],p_client_detail_info_tab->mac_addr[i][5]); lock = file_lock("networkmap"); memcpy(p_client_detail_info_tab->ip_addr[i], arp_ptr->source_ipaddr, 4); memcpy(p_client_detail_info_tab->mac_addr[i], arp_ptr->source_hwaddr, 6); p_client_detail_info_tab->exist[i] = 1; file_unlock(lock); /* real_num = p_client_detail_info_tab->detail_info_num; p_client_detail_info_tab->detail_info_num = i; #ifdef NMP_DB check_nmp_db(p_client_detail_info_tab, i); #endif FindAllApp(my_ipaddr, p_client_detail_info_tab); FindHostname(p_client_detail_info_tab); p_client_detail_info_tab->detail_info_num = real_num; */ break; } } //NMP_DEBUG("Out check!\n"); //i=0, table is empty. //i=num, no the same ip at table. if(i==p_client_detail_info_tab->ip_mac_num){ lock = file_lock("networkmap"); memcpy(p_client_detail_info_tab->ip_addr[p_client_detail_info_tab->ip_mac_num], arp_ptr->source_ipaddr, 4); memcpy(p_client_detail_info_tab->mac_addr[p_client_detail_info_tab->ip_mac_num], arp_ptr->source_hwaddr, 6); p_client_detail_info_tab->exist[p_client_detail_info_tab->ip_mac_num] = 1; #ifdef NMP_DB check_nmp_db(p_client_detail_info_tab, i); #endif p_client_detail_info_tab->ip_mac_num++; file_unlock(lock); #ifdef DEBUG //Write client info to file fp_ip=fopen("/var/client_ip_mac.txt", "a"); if (fp_ip==NULL) { NMP_DEBUG("File Open Error!\n"); } else { NMP_DEBUG_M("Fill: %d-> %d.%d\n", i,p_client_detail_info_tab->ip_addr[i][2],p_client_detail_info_tab->ip_addr[i][3]); fprintf(fp_ip, "%d.%d.%d.%d,%02X:%02X:%02X:%02X:%02X:%02X\n", p_client_detail_info_tab->ip_addr[i][0],p_client_detail_info_tab->ip_addr[i][1], p_client_detail_info_tab->ip_addr[i][2],p_client_detail_info_tab->ip_addr[i][3], p_client_detail_info_tab->mac_addr[i][0],p_client_detail_info_tab->mac_addr[i][1], p_client_detail_info_tab->mac_addr[i][2],p_client_detail_info_tab->mac_addr[i][3], p_client_detail_info_tab->mac_addr[i][4],p_client_detail_info_tab->mac_addr[i][5]); } fclose(fp_ip); #endif } } else { //Nomo ARP Packet or ARP response to other IP //Compare IP and IP buffer if not exist for(i=0; i<p_client_detail_info_tab->ip_mac_num; i++) { if( !memcmp(p_client_detail_info_tab->ip_addr[i], arp_ptr->source_ipaddr, 4) && !memcmp(p_client_detail_info_tab->mac_addr[i], arp_ptr->source_hwaddr, 6)) { NMP_DEBUG_M("Find the same IP/MAC at the table!\n"); break; } } if( i==p_client_detail_info_tab->ip_mac_num ) //Find a new IP or table is empty! Send an ARP request. { NMP_DEBUG("New device or IP/MAC changed!!\n"); if(memcmp(my_ipaddr, arp_ptr->source_ipaddr, 4)) sent_arppacket(arp_sockfd, arp_ptr->source_ipaddr); else NMP_DEBUG("New IP is the same as Router IP! Ignore it!\n"); } }//End of Nomo ARP Packet }//Source IP in the same subnetwork }//End of arp_getlen != -1 } // End of while for flush buffer if(!loop) break; /* int y = 0; while(p_client_detail_info_tab->type[y]!=0){ NMP_DEBUG("%d: %d.%d.%d.%d,%02X:%02X:%02X:%02X:%02X:%02X,%s,%d,%d,%d,%d,%d\n", y , p_client_detail_info_tab->ip_addr[y][0],p_client_detail_info_tab->ip_addr[y][1], p_client_detail_info_tab->ip_addr[y][2],p_client_detail_info_tab->ip_addr[y][3], p_client_detail_info_tab->mac_addr[y][0],p_client_detail_info_tab->mac_addr[y][1], p_client_detail_info_tab->mac_addr[y][2],p_client_detail_info_tab->mac_addr[y][3], p_client_detail_info_tab->mac_addr[y][4],p_client_detail_info_tab->mac_addr[y][5], p_client_detail_info_tab->device_name[y], p_client_detail_info_tab->type[y], p_client_detail_info_tab->http[y], p_client_detail_info_tab->printer[y], p_client_detail_info_tab->itune[y], p_client_detail_info_tab->exist[y]); y++; } */ //Find All Application of clients //NMP_DEBUG("\ndetail ? ip : %d ? %d\n\n", p_client_detail_info_tab->detail_info_num, p_client_detail_info_tab->ip_mac_num); if(p_client_detail_info_tab->detail_info_num < p_client_detail_info_tab->ip_mac_num) { //nvram_set("networkmap_status", "1"); if(tcapi_set("ClientList_Common", "status", "1")) NMP_DEBUG_M("set node(ClientList_Common:status) failed.\n"); FindAllApp(my_ipaddr, p_client_detail_info_tab); FindHostname(p_client_detail_info_tab); #ifdef DEBUG //Fill client detail info table fp_ip=fopen("/var/client_detail_info.txt", "a"); if (fp_ip==NULL) { NMP_DEBUG("File Open Error!\n"); } else { fprintf(fp_ip, "%s,%d,%d,%d,%d\n", p_client_detail_info_tab->device_name[p_client_detail_info_tab->detail_info_num], p_client_detail_info_tab->type[p_client_detail_info_tab->detail_info_num], p_client_detail_info_tab->http[p_client_detail_info_tab->detail_info_num], p_client_detail_info_tab->printer[p_client_detail_info_tab->detail_info_num], p_client_detail_info_tab->itune[p_client_detail_info_tab->detail_info_num]); fclose(fp_ip); } #endif #ifdef NMP_DB write_to_cfg_node(p_client_detail_info_tab); #endif p_client_detail_info_tab->detail_info_num++; } #ifdef NMP_DB else { NMP_DEBUG_M("commit_no, cli_no, updated: %d, %d, %d\n", commit_no, p_client_detail_info_tab->detail_info_num, client_updated); if( (commit_no != p_client_detail_info_tab->detail_info_num) || client_updated ) { NMP_DEBUG("Commit nmp client list\n"); //nvram_commit(); commit_no = p_client_detail_info_tab->detail_info_num; client_updated = 0; } } #endif if(p_client_detail_info_tab->detail_info_num == p_client_detail_info_tab->ip_mac_num) { //nvram_set("networkmap_status", "0"); // Done scanning and resolving NMP_DEBUG_M("Scan Finish!\n"); if(tcapi_set("ClientList_Common", "status", "0")) NMP_DEBUG_M("set node(ClientList_Common:status) failed.\n"); } } //End of main while loop SAFE_FREE(p_client_detail_info_tab); close(arp_sockfd); return 0; }
char *delete_nvram_contents(char *url,char *folder) { char *nv; char *nvp; char *p,*b; char *new_nv; int n; int i = 0; #ifdef NVRAM_ #ifdef USE_TCAPI char tmp[MAXLEN_TCAPI_MSG] = {0}; tcapi_get(AICLOUD, "usb_tokenfile", tmp); nv = my_malloc(strlen(tmp) + 1); //2014.10.20 by sherry malloc申请内存是否成功 //if(nv==NULL) // return NULL; sprintf(nv, "%s", tmp); p = nv; #else p = nv = strdup(nvram_safe_get("usb_tokenfile")); #endif #else FILE *fp; fp = fopen("/opt/etc/usb_tokenfile", "r"); if (fp == NULL) { nv = my_malloc(2); //2014.10.20 by sherry malloc申请内存是否成功 // if(nv==NULL) // return NULL; sprintf(nv, ""); } else { fseek( fp , 0 , SEEK_END ); int file_size; file_size = ftell( fp ); fseek(fp , 0 , SEEK_SET); nv = my_malloc(file_size + 2); //2014.10.20 by sherry malloc申请内存是否成功 // if(nv==NULL) // return NULL; fscanf(fp, "%[^\n]%*c", nv); p = nv; fclose(fp); } #endif nvp = my_malloc(strlen(url) + strlen(folder) + 2); //2014.10.20 by sherry malloc申请内存是否成功 //if(nvp==NULL) // return NULL; sprintf(nvp, "%s>%s", url, folder); if(strstr(nv, nvp) == NULL) { free(nvp); return nv; } if(!strcmp(nv, nvp)) { free(nvp); memset(nv, 0, sizeof(nv)); sprintf(nv, ""); return nv; } if(nv) { while((b = strsep(&p, "<")) != NULL) { if(strcmp(b, nvp)) { n = strlen(b); if(i == 0) { new_nv = my_malloc(n + 1); //2014.10.20 by sherry malloc申请内存是否成功 // if(new_nv==NULL) // return NULL; sprintf(new_nv, "%s", b); ++i; } else { new_nv = (char*)realloc(new_nv, strlen(new_nv) + n + 2); sprintf(new_nv, "%s<%s", new_nv, b); } } } free(nv); } free(nvp); return new_nv; }
int main(int argc, char *argv[]) { FILE *fp; char tmp[128]; int st_ftp_mode, st_max_user; unlink("/var/log.vsftpd"); if ((fp=fopen(VSFTPD_CONF, "r"))) { fclose(fp); unlink(VSFTPD_CONF); } if((fp = fopen(VSFTPD_CONF, "w")) == NULL) return -1; tcapi_get("Samba_Entry", "st_ftp_mode", tmp); st_ftp_mode = atoi(tmp); //if (nvram_match("st_ftp_mode", "2")) if (st_ftp_mode == 2) fprintf(fp, "anonymous_enable=NO\n"); else{ fprintf(fp, "anonymous_enable=YES\n"); fprintf(fp, "anon_upload_enable=YES\n"); fprintf(fp, "anon_mkdir_write_enable=YES\n"); fprintf(fp, "anon_other_write_enable=YES\n"); } fprintf(fp, "nopriv_user=root\n"); fprintf(fp, "write_enable=YES\n"); fprintf(fp, "local_enable=YES\n"); fprintf(fp, "chroot_local_user=YES\n"); fprintf(fp, "local_umask=000\n"); fprintf(fp, "dirmessage_enable=NO\n"); fprintf(fp, "xferlog_enable=NO\n"); fprintf(fp, "syslog_enable=NO\n"); fprintf(fp, "connect_from_port_20=YES\n"); // fprintf(fp, "listen=YES\n"); fprintf(fp, "listen%s=YES\n", //#ifdef RTCONFIG_IPV6 #ifdef TCSUPPORT_IPV6 //ipv6_enabled() ? "_ipv6" : ""); "_ipv6"); #else ""); #endif fprintf(fp, "pasv_enable=YES\n"); fprintf(fp, "ssl_enable=NO\n"); fprintf(fp, "tcp_wrappers=NO\n"); //strcpy(maxuser, nvram_safe_get("st_max_user")); //if ((atoi(maxuser)) > 0) tcapi_get("Samba_Entry", "st_max_user", tmp); st_max_user = atoi(tmp); if (st_max_user > 0) fprintf(fp, "max_clients=%d\n", st_max_user); else fprintf(fp, "max_clients=%s\n", "10"); fprintf(fp, "ftp_username=anonymous\n"); //fprintf(fp, "ftpd_banner=Welcome to ASUS %s FTP service.\n", nvram_safe_get("productid")); fprintf(fp, "ftpd_banner=Welcome to ASUS %s FTP service.\n", "DSL-N66U"); //tmp fprintf(fp, "hide_file={.router_temp*}\n"); // update codepage eval("modprobe", "-r", "nls_cp936"); eval("modprobe", "-r", "nls_cp950"); tcapi_get("Samba_Entry", "ftp_lang", tmp); //if (strcmp(nvram_safe_get("ftp_lang"), "EN") != 0) if (strcmp(tmp, "EN")) { fprintf(fp, "enable_iconv=YES\n"); //if (nvram_match("ftp_lang", "TW")) { if (!strcmp(tmp, "TW")) { fprintf(fp, "remote_charset=cp950\n"); eval("modprobe", "nls_cp950"); } //else if (nvram_match("ftp_lang", "CN")) { else if (!strcmp(tmp, "CN")) { fprintf(fp, "remote_charset=cp936\n"); eval("modprobe", "nls_cp936"); } } fclose(fp); return 0; }
void start_pptpd(void) { int ret = 0, manual_dns = 0, pptpd_opt = 0; FILE *fp; char buf[MAXLEN_TCAPI_MSG]; char lan_ipaddr[16] = {0}; int pid = getpid(); _dprintf("start_pptpd: getpid= %d\n", pid); //if(getpid() != 1) { //notify_rc("start_pptpd"); //return; //} if (!tcapi_match(VPN_DATA, "pptpd_enable", "1")) { return; } // cprintf("stop vpn modules\n"); // stop_vpn_modules (); // Create directory for use by pptpd daemon and its supporting files mkdir("/tmp/pptpd", 0744); cprintf("open options file\n"); // Create options file that will be unique to pptpd to avoid interference // with pppoe and pptp fp = fopen("/tmp/pptpd/options.pptpd", "w"); fprintf(fp, "logfile /var/log/pptpd-pppd.log\n"); //fprintf(fp, "debug dump logfd 2 nodetach\n"); if (tcapi_match(VPN_DATA, "pptpd_radius", "1")) fprintf(fp, "plugin radius.so\nplugin radattr.so\n" "radius-config-file /tmp/pptpd/radius/radiusclient.conf\n"); //cprintf("check if wan_wins = zero\n"); //int nowins = 0; //if (nvram_match("wan_wins", "0.0.0.0")) { //nvram_set("wan_wins", ""); //nowins = 1; //} //if (strlen(nvram_safe_get("wan_wins")) == 0) //nowins = 1; cprintf("write config\n"); fprintf(fp, "lock\n" "name *\n" "proxyarp\n" // "ipcp-accept-local\n" // "ipcp-accept-remote\n" "lcp-echo-failure 10\n" "lcp-echo-interval 6\n" "deflate 0\n" "auth\n" "-chap\n" "nomppe-stateful\n"); pptpd_opt = tcapi_get_int(VPN_DATA, "pptpd_chap"); fprintf(fp, "%smschap\n", (pptpd_opt == 0 || pptpd_opt & 1) ? "+" : "-"); fprintf(fp, "%smschap-v2\n", (pptpd_opt == 0 || pptpd_opt & 2) ? "+" : "-"); pptpd_opt = tcapi_get_int(VPN_DATA, "pptpd_mppe"); if (pptpd_opt == 0) pptpd_opt = 1 | 4 | 8; if (pptpd_opt & (1 | 2 | 4)) { fprintf(fp, "%s", (pptpd_opt & 8) ? "" : "require-mppe\n"); fprintf(fp, "%smppe-128\n", (pptpd_opt & 1) ? "require-" : "no"); //fprintf(fp, "%smppe-56\n", (pptpd_opt & 2) ? "require-" : "no"); fprintf(fp, "%smppe-40\n", (pptpd_opt & 4) ? "require-" : "no"); } else fprintf(fp, "nomppe nomppc\n"); fprintf(fp, "ms-ignore-domain\n" "chap-secrets /tmp/pptpd/chap-secrets\n" "ip-up-script /tmp/pptpd/ip-up\n" "ip-down-script /tmp/pptpd/ip-down\n" "mtu %d\n" "mru %d\n", tcapi_get_int(VPN_DATA, "pptpd_mtu"), tcapi_get_int(VPN_DATA, "pptpd_mru")); //WINS Server //if (!nowins) { //fprintf(fp, "ms-wins %s\n", nvram_safe_get("wan_wins")); //} memset(buf, 0, sizeof(buf)); tcapi_get(VPN_DATA, "pptpd_wins1", buf); if(strlen(buf)) { fprintf(fp, "ms-wins %s\n", buf); } memset(buf, 0, sizeof(buf)); tcapi_get(VPN_DATA, "pptpd_wins2", buf); if(strlen(buf)) { fprintf(fp, "ms-wins %s\n", buf); } //DNS Server memset(buf, 0, sizeof(buf)); tcapi_get(VPN_DATA, "pptpd_dns1", buf); if(strlen(buf)) { fprintf(fp, "ms-dns %s\n", buf); manual_dns=1; } memset(buf, 0, sizeof(buf)); tcapi_get(VPN_DATA, "pptpd_dns2", buf); if(strlen(buf)) { fprintf(fp, "ms-dns %s\n", buf); manual_dns=1; } tcapi_get("Lan_Entry0", "IP", lan_ipaddr); if(!manual_dns && strcmp(lan_ipaddr, "")) fprintf(fp, "ms-dns %s\n", lan_ipaddr); // force ppp interface starting from 20 fprintf(fp, "minunit 20\n"); // Following is all crude and need to be revisited once testing confirms // that it does work // Should be enough for testing.. if (tcapi_match(VPN_DATA, "pptpd_radius", "1")) { char pptpd_radserver[128] = {0}; char pptpd_radpass[128] = {0}; char pptpd_radport[128] = {0}; char pptpd_acctport[128] = {0}; if (tcapi_get(VPN_DATA, "pptpd_radserver", pptpd_radserver) == TCAPI_PROCESS_OK && tcapi_get(VPN_DATA, "pptpd_radpass", pptpd_radpass) == TCAPI_PROCESS_OK) { fclose(fp); mkdir("/tmp/pptpd/radius", 0744); if (tcapi_get(VPN_DATA, "pptpd_radport", pptpd_radport) != TCAPI_PROCESS_OK) strcpy(pptpd_radport, "radius"); fp = fopen("/tmp/pptpd/radius/radiusclient.conf", "w"); fprintf(fp, "auth_order radius\n" "login_tries 4\n" "login_timeout 60\n" "radius_timeout 10\n" "nologin /etc/nologin\n" "servers /tmp/pptpd/radius/servers\n" "dictionary /etc/dictionary\n" "seqfile /var/run/radius.seq\n" "mapfile /etc/port-id-map\n" "radius_retries 3\n" "authserver %s:%s\n", pptpd_radserver, pptpd_radport); if (tcapi_get(VPN_DATA, "pptpd_acctport", pptpd_acctport) != TCAPI_PROCESS_OK) strcpy(pptpd_acctport, "radacct"); fprintf(fp, "acctserver %s:%s\n", pptpd_radserver, pptpd_acctport); fclose(fp); fp = fopen("/tmp/pptpd/radius/servers", "w"); fprintf(fp, "%s\t%s\n", pptpd_radserver, pptpd_radpass); fclose(fp); } else fclose(fp); } else fclose(fp); // Create pptpd.conf options file for pptpd daemon fp = fopen("/tmp/pptpd/pptpd.conf", "w"); memset(buf, 0, sizeof(buf)); fprintf(fp, "bcrelay %s\n", tcapi_get_string(VPN_DATA, "pptpd_broadcast", buf)); memset(buf, 0, sizeof(buf)); fprintf(fp, "localip %s\n" "remoteip %s\n", lan_ipaddr, tcapi_get_string(VPN_DATA, "pptpd_clients", buf)); fclose(fp); // Create ip-up and ip-down scripts that are unique to pptpd to avoid // interference with pppoe and pptp /* * adjust for tunneling overhead (mtu - 40 byte IP - 108 byte tunnel * overhead) */ //if (nvram_match("mtu_enable", "1")) //mss = atoi(nvram_safe_get("wan_mtu")) - 40 - 108; //else //mss = 1500 - 40 - 108; char bcast[32]; strcpy(bcast, lan_ipaddr); memset(buf, 0, sizeof(buf)); get_broadcast(bcast, tcapi_get_string("Lan_Entry0", "netmask", buf)); memset(buf, 0, sizeof(buf)); tcapi_get(VPN_DATA, "pptpd_ipup_script", buf); fp = fopen("/tmp/pptpd/ip-up", "w"); fprintf(fp, "#!/bin/sh\n" "startservice set_routes\n" // reinitialize "echo $PPPD_PID $1 $5 $6 $PEERNAME >> /tmp/pptp_connected\n" "iptables -I FORWARD -i $1 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu\n" "iptables -I INPUT -i $1 -j ACCEPT\n" "iptables -I FORWARD -i $1 -j ACCEPT\n" "iptables -t nat -I PREROUTING -i $1 -p udp -m udp --sport 9 -j DNAT --to-destination %s " // rule for wake on lan over pptp tunnel "%s\n", bcast, buf); fclose(fp); memset(buf, 0, sizeof(buf)); tcapi_get(VPN_DATA, "pptpd_ipdown_script", buf); fp = fopen("/tmp/pptpd/ip-down", "w"); fprintf(fp, "#!/bin/sh\n" "grep -v $1 /tmp/pptp_connected > /tmp/pptp_connected.new\n" "mv /tmp/pptp_connected.new /tmp/pptp_connected\n" "iptables -D FORWARD -i $1 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu\n" "iptables -D INPUT -i $1 -j ACCEPT\n" "iptables -D FORWARD -i $1 -j ACCEPT\n" "iptables -t nat -D PREROUTING -i $1 -p udp -m udp --sport 9 -j DNAT --to-destination %s " // rule for wake on lan over pptp tunnel "%s\n", bcast, buf); fclose(fp); chmod("/tmp/pptpd/ip-up", 0744); chmod("/tmp/pptpd/ip-down", 0744); // Exctract chap-secrets from nvram write_chap_secret("/tmp/pptpd/chap-secrets"); chmod("/tmp/pptpd/chap-secrets", 0600); // Execute pptpd daemon ret = eval("pptpd", "-c", "/tmp/pptpd/pptpd.conf", "-o", "/tmp/pptpd/options.pptpd"); _dprintf("start_pptpd: ret= %d\n", ret); //dd_syslog(LOG_INFO, "pptpd : pptp daemon successfully started\n"); return; }
void dhcpExtractClasslessRoute(uint8_t *data, int len) { int optionlen, index, i; int value, remain; uint8_t ip[4]={0,0,0,0}; struct in_addr destmask; struct in_addr routeIP; char cmd[128]; char tmp[20]; uint8_t metric = 2; uint8_t defRtCh = 0; if(!tcapi_get("Dhcpd_Option121","dhcpmetric", tmp)) metric = atoi(tmp); if(!tcapi_get("Dhcpd_Option121","changeDefRt", tmp)) defRtCh = atoi(tmp); index = 0; optionlen = len; if (optionlen < 5) return; while(index<optionlen){ memset(ip, 0, 4); // the max IPv4 address is 32 bits if(data[index] > 32) { tcdbg_printf("parser option121 error ----- IP error.\r\n"); return; } if( 0 == data[index] ) { if(defRtCh == 0){ index += 5; continue; } else{ destmask.s_addr = 0; //destination mask routeIP.s_addr = get32(&data[index+1]); index += 5; } } else { value = (data[index]-1)/8; remain = data[index]%8; if (!remain) remain = 8; if(index+value+1 >= optionlen){ tcdbg_printf("parser option121 error ----- expand lenth.\r\n"); return; } data[index+value+1] &= ~(0xFF >> remain); memcpy(ip,&data[index+1],value+1); //destination IP destmask.s_addr = (0xFFFFFFFF << (32 -data[index])); //destination mask routeIP.s_addr = get32(&data[index+value+2]); //route IP index += (value+6); if(get32(ip)==0){ continue; } } if (routeIP.s_addr) { if((get32(ip) == 0) && (destmask.s_addr == 0)) { memset (cmd, 0, 128); strcpy(cmd, "/sbin/route del default"); system(cmd); } strcpy(tmp, inet_ntoa(destmask)); //inet_ntoa can't be called twice in an expression memset (cmd, 0, 128); sprintf( cmd, "/sbin/route add -net %d.%d.%d.%d netmask %s gw %s metric %d", ip[0], ip[1], ip[2], ip[3], tmp, inet_ntoa(routeIP), metric); system(cmd); } } return; }
int main(int argc, char *argv[]) { FILE *fp; int n=0; char *p_computer_name = NULL; disk_info_t *follow_disk, *disks_info = NULL; partition_info_t *follow_partition; char *mount_folder; int result, node_layer, samba_right; int sh_num; char **folder_list = NULL; int acc_num; char **account_list; char tmp[128]; unlink("/var/log.samba"); if ((fp=fopen(SAMBA_CONF, "r"))) { fclose(fp); unlink(SAMBA_CONF); } if((fp = fopen(SAMBA_CONF, "w")) == NULL) goto confpage; fprintf(fp, "[global]\n"); //if (nvram_safe_get("st_samba_workgroup")) if(!tcapi_get("Samba_Entry", "st_samba_workgroup", tmp)) //fprintf(fp, "workgroup = %s\n", nvram_safe_get("st_samba_workgroup")); fprintf(fp, "workgroup = %s\n", tmp); #if 0 if (nvram_safe_get("computer_name")) { fprintf(fp, "netbios name = %s\n", nvram_safe_get("computer_name")); fprintf(fp, "server string = %s\n", nvram_safe_get("computer_name")); } #else //p_computer_name = nvram_get("computer_name") && is_valid_hostname(nvram_get("computer_name")) ? nvram_get("computer_name") : nvram_safe_get("productid"); tcapi_get("Samba_Entry", "NetBiosName", tmp); //check NetBiosName in web page p_computer_name = tmp; if (p_computer_name) { fprintf(fp, "netbios name = %s\n", p_computer_name); fprintf(fp, "server string = %s\n", p_computer_name); } #endif fprintf(fp, "unix charset = UTF8\n"); // ASUS add fprintf(fp, "display charset = UTF8\n"); // ASUS add fprintf(fp, "log file = /var/log.samba\n"); fprintf(fp, "log level = 0\n"); fprintf(fp, "max log size = 5\n"); /* share mode */ tcapi_get("Samba_Entry", "st_samba_mode", tmp); if (!strcmp(tmp, "1") || !strcmp(tmp, "3")) { //if (!strcmp(nvram_safe_get("st_samba_mode"), "1") || !strcmp(nvram_safe_get("st_samba_mode"), "3")) { fprintf(fp, "security = SHARE\n"); fprintf(fp, "guest only = yes\n"); } //else if (!strcmp(nvram_safe_get("st_samba_mode"), "2") || !strcmp(nvram_safe_get("st_samba_mode"), "4")) { else if (!strcmp(tmp, "2") || !strcmp(tmp, "4")) { fprintf(fp, "security = USER\n"); fprintf(fp, "guest ok = no\n"); fprintf(fp, "map to guest = Bad User\n"); } else{ usb_dbg("samba mode: no\n"); goto confpage; } fprintf(fp, "encrypt passwords = yes\n"); fprintf(fp, "pam password change = no\n"); fprintf(fp, "null passwords = yes\n"); // ASUS add fprintf(fp, "force directory mode = 0777\n"); fprintf(fp, "force create mode = 0777\n"); /* max users */ if (!tcapi_get("Samba_Entry", "st_max_user", tmp)) fprintf(fp, "max connections = %s\n", tmp); //if (strcmp(nvram_safe_get("st_max_user"), "") != 0) //fprintf(fp, "max connections = %s\n", nvram_safe_get("st_max_user")); fprintf(fp, "socket options = TCP_NODELAY SO_KEEPALIVE SO_RCVBUF=65536 SO_SNDBUF=65536\n"); fprintf(fp, "use sendfile = no\n"); fprintf(fp, "obey pam restrictions = no\n"); fprintf(fp, "use spne go = no\n"); // ASUS add fprintf(fp, "client use spnego = no\n"); // ASUS add fprintf(fp, "disable spoolss = yes\n"); // ASUS add fprintf(fp, "host msdfs = no\n"); // ASUS add fprintf(fp, "strict allocate = No\n"); // ASUS add // fprintf(fp, "mangling method = hash2\n"); // ASUS add fprintf(fp, "bind interfaces only = yes\n"); // ASUS add fprintf(fp, "interfaces = lo br0\n"); //fprintf(fp, "interfaces = lo br0 %s\n", (!nvram_match("sw_mode", "3") ? nvram_safe_get("wan0_ifname") : "")); // fprintf(fp, "dns proxy = no\n"); // J-- // fprintf(fp, "domain master = no\n"); // J++ // fprintf(fp, "wins support = no\n"); // J++ // fprintf(fp, "printable = no\n"); // J++ // fprintf(fp, "browseable = yes\n"); // J++ // fprintf(fp, "security mask = 0777\n"); // J++ // fprintf(fp, "force security mode = 0\n"); // J++ // fprintf(fp, "directory security mask = 0777\n"); // J++ // fprintf(fp, "force directory security mode = 0\n"); // J++ fprintf(fp, "map archive = no\n"); fprintf(fp, "map hidden = no\n"); fprintf(fp, "map read only = no\n"); fprintf(fp, "map system = no\n"); fprintf(fp, "store dos attributes = yes\n"); fprintf(fp, "dos filemode = yes\n"); fprintf(fp, "dos filetimes = yes\n"); fprintf(fp, "dos filetime resolution = yes\n"); disks_info = read_disk_data(); if (disks_info == NULL) { usb_dbg("Couldn't get disk list when writing smb.conf!\n"); goto confpage; } /* share */ tcapi_get("Samba_Entry", "st_samba_mode", tmp); if (!strcmp(tmp, "0")) { //if (!strcmp(nvram_safe_get("st_samba_mode"), "0") || !strcmp(nvram_safe_get("st_samba_mode"), "")) { ; } else if (!strcmp(tmp, "1")) { //else if (!strcmp(nvram_safe_get("st_samba_mode"), "1")) { usb_dbg("samba mode: share\n"); for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) { for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) { if (follow_partition->mount_point == NULL) continue; mount_folder = strrchr(follow_partition->mount_point, '/')+1; fprintf(fp, "[%s]\n", mount_folder); fprintf(fp, "comment = %s's %s\n", follow_disk->tag, mount_folder); fprintf(fp, "veto files = /.__*.txt*/asusware*/asus_lighttpdpasswd/\n"); fprintf(fp, "path = %s\n", follow_partition->mount_point); fprintf(fp, "writeable = yes\n"); } } } else if (!strcmp(tmp, "2")) { //else if (!strcmp(nvram_safe_get("st_samba_mode"), "2")) { usb_dbg("samba mode: share\n"); for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) { for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) { if (follow_partition->mount_point == NULL) continue; mount_folder = strrchr(follow_partition->mount_point, '/')+1; node_layer = get_permission(NULL, follow_partition->mount_point, NULL, "cifs"); if(node_layer == 3){ fprintf(fp, "[%s]\n", mount_folder); fprintf(fp, "comment = %s's %s\n", follow_disk->tag, mount_folder); fprintf(fp, "path = %s\n", follow_partition->mount_point); fprintf(fp, "writeable = yes\n"); } else{ //result = get_all_folder(follow_partition->mount_point, &sh_num, &folder_list); result = get_folder_list(follow_partition->mount_point, &sh_num, &folder_list); if (result < 0){ free_2_dimension_list(&sh_num, &folder_list); continue; } for (n = 0; n < sh_num; ++n){ samba_right = get_permission(NULL, follow_partition->mount_point, folder_list[n], "cifs"); if (samba_right < 0 || samba_right > 3) samba_right = DEFAULT_SAMBA_RIGHT; if(samba_right > 0){ fprintf(fp, "[%s (at %s)]\n", folder_list[n], mount_folder); fprintf(fp, "comment = %s's %s in %s\n", mount_folder, folder_list[n], follow_disk->tag); fprintf(fp, "path = %s/%s\n", follow_partition->mount_point, folder_list[n]); if(samba_right == 3) fprintf(fp, "writeable = yes\n"); else fprintf(fp, "writeable = no\n"); } } free_2_dimension_list(&sh_num, &folder_list); } } } } else if (!strcmp(tmp, "3")) { //else if (!strcmp(nvram_safe_get("st_samba_mode"), "3")) { usb_dbg("samba mode: user\n"); // get the account list if (get_account_list(&acc_num, &account_list) < 0) { usb_dbg("Can't read the account list.\n"); free_2_dimension_list(&acc_num, &account_list); goto confpage; } for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) { for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) { if (follow_partition->mount_point == NULL) continue; mount_folder = strrchr(follow_partition->mount_point, '/')+1; // 1. get the folder list if (get_folder_list(follow_partition->mount_point, &sh_num, &folder_list) < 0) { free_2_dimension_list(&sh_num, &folder_list); } // 2. start to get every share for (n = -1; n < sh_num; ++n) { int i, first; if(n == -1){ fprintf(fp, "[%s]\n", mount_folder); fprintf(fp, "comment = %s's %s\n", follow_disk->tag, mount_folder); fprintf(fp, "path = %s\n", follow_partition->mount_point); } else{ fprintf(fp, "[%s (at %s)]\n", folder_list[n], mount_folder); fprintf(fp, "comment = %s's %s in %s\n", mount_folder, folder_list[n], follow_disk->tag); fprintf(fp, "path = %s/%s\n", follow_partition->mount_point, folder_list[n]); } fprintf(fp, "valid users = "); first = 1; for (i = 0; i < acc_num; ++i) { if(n == -1) samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs"); else samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs"); if (first == 1) first = 0; else fprintf(fp, ", "); fprintf(fp, "%s", account_list[i]); } fprintf(fp, "\n"); fprintf(fp, "invalid users = "); first = 1; for (i = 0; i < acc_num; ++i) { if(n == -1) samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs"); else samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs"); if (samba_right >= 1) continue; if (first == 1) first = 0; else fprintf(fp, ", "); fprintf(fp, "%s", account_list[i]); } fprintf(fp, "\n"); fprintf(fp, "read list = "); first = 1; for (i = 0; i < acc_num; ++i) { if(n == -1) samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs"); else samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs"); if (samba_right < 1) continue; if (first == 1) first = 0; else fprintf(fp, ", "); fprintf(fp, "%s", account_list[i]); } fprintf(fp, "\n"); fprintf(fp, "write list = "); first = 1; for (i = 0; i < acc_num; ++i) { if(n == -1) samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs"); else samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs"); if (samba_right < 2) continue; if (first == 1) first = 0; else fprintf(fp, ", "); fprintf(fp, "%s", account_list[i]); } fprintf(fp, "\n"); } free_2_dimension_list(&sh_num, &folder_list); } } free_2_dimension_list(&acc_num, &account_list); } else if (!strcmp(tmp, "4")) { //else if (!strcmp(nvram_safe_get("st_samba_mode"), "4")) { usb_dbg("samba mode: user\n"); // get the account list if (get_account_list(&acc_num, &account_list) < 0) { usb_dbg("Can't read the account list.\n"); free_2_dimension_list(&acc_num, &account_list); goto confpage; } for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) { for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) { if (follow_partition->mount_point == NULL) continue; mount_folder = strrchr(follow_partition->mount_point, '/')+1; // 1. get the folder list if (get_folder_list(follow_partition->mount_point, &sh_num, &folder_list) < 0) { free_2_dimension_list(&sh_num, &folder_list); } // 2. start to get every share for (n = 0; n < sh_num; ++n) { int i, first; fprintf(fp, "[%s (at %s)]\n", folder_list[n], mount_folder); fprintf(fp, "comment = %s's %s in %s\n", mount_folder, folder_list[n], follow_disk->tag); fprintf(fp, "path = %s/%s\n", follow_partition->mount_point, folder_list[n]); fprintf(fp, "valid users = "); first = 1; for (i = 0; i < acc_num; ++i) { if(n == -1) samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs"); else samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs"); if (first == 1) first = 0; else fprintf(fp, ", "); fprintf(fp, "%s", account_list[i]); } fprintf(fp, "\n"); fprintf(fp, "invalid users = "); first = 1; for (i = 0; i < acc_num; ++i) { samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs"); if (samba_right >= 1) continue; if (first == 1) first = 0; else fprintf(fp, ", "); fprintf(fp, "%s", account_list[i]); } fprintf(fp, "\n"); fprintf(fp, "read list = "); first = 1; for (i = 0; i < acc_num; ++i) { samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs"); if (samba_right < 1) continue; if (first == 1) first = 0; else fprintf(fp, ", "); fprintf(fp, "%s", account_list[i]); } fprintf(fp, "\n"); fprintf(fp, "write list = "); first = 1; for (i = 0; i < acc_num; ++i) { samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs"); if (samba_right < 2) continue; if (first == 1) first = 0; else fprintf(fp, ", "); fprintf(fp, "%s", account_list[i]); } fprintf(fp, "\n"); } free_2_dimension_list(&sh_num, &folder_list); } } free_2_dimension_list(&acc_num, &account_list); } confpage: if(fp != NULL) fclose(fp); free_disk_data(&disks_info); return 0; }
int check_config_path(int is_read_config) { DEBUG("check_config_path start\n"); int i; int flag; char *nv; char *nvp; char *new_nv; int nv_len; int is_path_change = 0; #ifdef NVRAM_ #ifdef USE_TCAPI char tmp[MAXLEN_TCAPI_MSG] = {0}; tcapi_get(AICLOUD, "usb_tokenfile", tmp); nv = my_malloc(strlen(tmp) + 1); //2014.10.20 by sherry malloc申请内存是否成功 //if(nv==NULL) // return NULL; sprintf(nv, "%s", tmp); #else nv = strdup(nvram_safe_get("usb_tokenfile")); #endif #else FILE *fp; fp = fopen(TOKENFILE_RECORD, "r"); if(fp == NULL) { nv = my_malloc(2); //2014.10.20 by sherry malloc申请内存是否成功 //if(nv==NULL) // return NULL; sprintf(nv, ""); } else { fseek( fp, 0, SEEK_END ); int file_size; file_size = ftell( fp ); fseek(fp, 0, SEEK_SET); //nv = (char *)malloc( file_size * sizeof( char ) ); nv = my_malloc(file_size + 2); //2014.10.20 by sherry malloc申请内存是否成功 //if(nv==NULL) //return NULL; //fread(nv , file_size , sizeof(char) , fp); fscanf(fp, "%[^\n]%*c", nv); fclose(fp); } #endif nv_len = strlen(nv); DEBUG("nv_len = %d\n", nv_len); for(i = 0; i < smb_config.dir_num; i++) { flag = 0; tokenfile_info_tmp = tokenfile_info_start->next; while(tokenfile_info_tmp != NULL) { if( !strcmp(tokenfile_info_tmp->url, smb_config.multrule[i]->server_root_path) && !strcmp(tokenfile_info_tmp->folder, smb_config.multrule[i]->client_root_path)) { if(strcmp(tokenfile_info_tmp->mountpath, smb_config.multrule[i]->mount_path)) { memset(smb_config.multrule[i]->mount_path, 0, sizeof(smb_config.multrule[i]->mount_path)); sprintf(smb_config.multrule[i]->mount_path, "%s", tokenfile_info_tmp->mountpath); memset(smb_config.multrule[i]->client_root_path, 0, sizeof(smb_config.multrule[i]->client_root_path)); sprintf(smb_config.multrule[i]->client_root_path, "%s%s", tokenfile_info_tmp->mountpath,tokenfile_info_tmp->folder); is_path_change = 1; } if(!is_read_config) { if(g_pSyncList[i]->sync_disk_exist == 0) is_path_change = 1; //plug the disk and the mout_path not change } flag = 1; break; } tokenfile_info_tmp = tokenfile_info_tmp->next; } //printf("flag = %d\n", flag); if(!flag) { nvp = my_malloc(strlen(smb_config.multrule[i]->server_root_path) + strlen(smb_config.multrule[i]->client_root_path) + 2); //2014.10.20 by sherry malloc申请内存是否成功 //if(nvp==NULL) // return NULL; sprintf(nvp, "%s>%s", smb_config.multrule[i]->server_root_path, smb_config.multrule[i]->client_root_path); if(!is_read_config) { if(g_pSyncList[i]->sync_disk_exist == 1) is_path_change = 2; //remove the disk and the mout_path not change } DEBUG("write nvram and tokenfile if before\n"); if(strstr(nv, nvp) == NULL) { DEBUG("write nvram and tokenfile if behind"); if(initial_tokenfile_info_data(&tokenfile_info_tmp) == NULL) { return -1; } tokenfile_info_tmp->url = my_malloc(strlen(smb_config.multrule[i]->server_root_path) + 1); //2014.10.20 by sherry malloc申请内存是否成功 // if(tokenfile_info_tmp->url==NULL) // return NULL; sprintf(tokenfile_info_tmp->url, "%s", smb_config.multrule[i]->server_root_path); tokenfile_info_tmp->mountpath = my_malloc(strlen(smb_config.multrule[i]->mount_path) + 1); //2014.10.20 by sherry malloc申请内存是否成功 //if(tokenfile_info_tmp->mountpath==NULL) // return NULL; sprintf(tokenfile_info_tmp->mountpath, "%s", smb_config.multrule[i]->mount_path); tokenfile_info_tmp->folder = my_malloc(strlen(smb_config.multrule[i]->client_root_path) + 1); //2014.10.20 by sherry malloc申请内存是否成功 //if(tokenfile_info_tmp->folder==NULL) // return NULL; sprintf(tokenfile_info_tmp->folder, "%s", smb_config.multrule[i]->client_root_path); tokenfile_info->next = tokenfile_info_tmp; tokenfile_info = tokenfile_info_tmp; write_to_tokenfile(smb_config.multrule[i]->mount_path); if(nv_len) { new_nv = my_malloc(strlen(nv) + strlen(nvp) + 2); //2014.10.20 by sherry malloc申请内存是否成功 // if(new_nv==NULL) // return NULL; sprintf(new_nv, "%s<%s", nv,nvp); } else { new_nv = my_malloc(strlen(nvp) + 1); //2014.10.20 by sherry malloc申请内存是否成功 //if(new_nv==NULL) // return NULL; sprintf(new_nv, "%s", nvp); } #ifdef NVRAM_ write_to_nvram(new_nv, "usb_tokenfile"); #else write_to_smb_tokenfile(new_nv); #endif free(new_nv); } free(nvp); } } free(nv); return is_path_change; }