int main(int argc, char* argv[]) { int ch; /** Default global values **/ memset(&CXPASSWD,0,sizeof(CXPASSWD)); strcpy(CXPASSWD.PasswdFile, ""); CXPASSWD.ReadStdin = 0; /** Check for config file options on the command line **/ while ((ch=getopt(argc,argv,"f:u:p:P")) > 0) { switch (ch) { case 'f': strtcpy(CXPASSWD.PasswdFile, optarg, sizeof(CXPASSWD.PasswdFile)); break; case 'u': strtcpy(CXPASSWD.UserName, optarg, sizeof(CXPASSWD.UserName)); break; case 'p': strtcpy(CXPASSWD.Password, optarg, sizeof(CXPASSWD.Password)); break; case 'P': CXPASSWD.ReadStdin = 1; break; default: case '?': case 'h': printf("Usage: cxpasswd [-u <username>] [-p <password>] [-P] [-f <passwdfile>]\n"); exit(0); } } mtInitialize(0, start); return 0; }
/** * Insert an entry into the database list and fill it with * path and if available, mp3 tag info. */ mptitle *insertTitle( mptitle *base, const char *path ) { mptitle *root; root = ( mptitle* ) falloc( 1, sizeof( mptitle ) ); if( NULL == base ) { base=root; base->next=base; base->prev=base; } else { root->next=base->next; root->prev=base; base->next=root; root->next->prev=root; } /* remove musicdir from path */ if( ( getConfig()->musicdir != NULL ) && ( strstr( path, getConfig()->musicdir ) != path ) ) { strtcpy( root->path, path, MAXPATHLEN ); } else { strtcpy( root->path, path+strlen(getConfig()->musicdir), MAXPATHLEN ); } fillTagInfo( root ); return root; }
/*** mssGenCred - generate credential used for authentication. This can *** be stored in a cxpasswd file. The credential points to a buffer where *** we can store the encrypted version of the password. 'salt' and 'salt_len' *** should indicate a series of random bytes. How many we use depends on *** whether the system supports MD5 passwords or not. cred_maxlen indicates *** the size of the buffer pointed to by credential. If there is not enough *** room, then we fail (return -1). *** *** Optimum salt length for MD5 passwords is 4 bytes - we expand it to 8 hex *** bytes. Salt should be full-range random bytes (0x00 - 0xFF). *** *** Successful return is 0. ***/ int mssGenCred(char* salt, int salt_len, char* password, char* credential, int cred_maxlen) { char salt_chars[] = "0123456789abcdef"; char salt_buf[9]; char *ptr; char *dstptr; /** Minimum salt length is 1 byte **/ if (salt_len < 1) return -1; /** Expand the salt to (up to) 8 bytes **/ ptr = salt; dstptr = salt_buf; while (*ptr) { *(dstptr++) = salt_chars[ptr[0] & 0xF]; *(dstptr++) = salt_chars[(ptr[0]>>4) & 0xF]; ptr++; } *dstptr = '\0'; /** Try MD5 style **/ if (cred_maxlen >= 35) { /** Create initial salt for crypt() **/ snprintf(credential, 35, "$1$%s$", salt_buf); /** Encrypt the password **/ ptr = crypt(password, credential); /** Success? **/ if (ptr && strlen(ptr) >= 27) { strtcpy(credential, ptr, cred_maxlen); return 0; } } /** Try DES style **/ if (cred_maxlen >= 14) { /** Create initial salt for crypt() **/ snprintf(credential, 14, "%.2s", salt_buf); /** Encrypt the password **/ ptr = crypt(password, credential); /** Success? **/ if (ptr) { strtcpy(credential, ptr, cred_maxlen); return 0; } } return -1; }
/*** AddRule: add a declarative osrc rule to the generated document. ***/ int htosrc_internal_AddRule(pHtSession s, pWgtrNode tree, char* treename, pWgtrNode sub_tree) { char ruletype[32]; int query_delay; int min_chars; int trailing_wildcard; int leading_wildcard; char fieldname[64]; char* ptr; pExpression code; /** Get type of rule **/ if (wgtrGetPropertyValue(sub_tree, "ruletype", DATA_T_STRING, POD(&ptr)) != 0) { mssError(1, "HTOSRC", "ruletype is required for widget/osrc-rule"); return -1; } strtcpy(ruletype, ptr, sizeof(ruletype)); /** Handle the rule based on the type **/ if (!strcmp(ruletype, "relationship")) { } else if (!strcmp(ruletype, "filter")) { trailing_wildcard = htrGetBoolean(sub_tree, "trailing_wildcard", 1); leading_wildcard = htrGetBoolean(sub_tree, "leading_wildcard", 0); if (wgtrGetPropertyValue(sub_tree, "min_chars", DATA_T_INTEGER, POD(&min_chars)) != 0) min_chars = 3; if (wgtrGetPropertyValue(sub_tree, "query_delay", DATA_T_INTEGER, POD(&query_delay)) != 0) query_delay = 500; if (wgtrGetPropertyValue(sub_tree, "fieldname", DATA_T_STRING, POD(&ptr)) == 0) strtcpy(fieldname, ptr, sizeof(fieldname)); else { mssError(1, "HTOSRC", "fieldname is required for widget/osrc-rule of type 'filter'"); return -1; } /** Get target **/ if (wgtrGetPropertyType(sub_tree,"value") == DATA_T_CODE) { wgtrGetPropertyValue(sub_tree,"value",DATA_T_CODE,POD(&code)); htrAddExpression(s, treename, wgtrGetDName(sub_tree), code); } /** Write the init line **/ htrAddScriptInit_va(s, " nodes[\"%STR&SYM\"].AddRule('%STR&SYM', {dname:'%STR&SYM', field:'%STR&ESCQ', qd:%INT, mc:%INT, tw:%INT, lw:%INT});\n", treename, ruletype, wgtrGetDName(sub_tree), fieldname, query_delay, min_chars, trailing_wildcard, leading_wildcard); } else if (!strcmp(ruletype, "keying")) { } return 0; }
long long test(char** tname) { int i,rval; int iter; unsigned char buf[44]; /** ** Main reason to have both a 1 char and 2 char test is that ** the compiler's optimization seems to partly unroll the ** loop into a copy-first-char and then copy-subsequent-chars ** sections (since 1st char requires no index offsets) **/ *tname = "strtcpy-08 strtcpy() copy to 2 char buffer"; iter = 800000; for(i=0; i<iter; i++) { buf[43] = '\n'; buf[42] = '\0'; buf[41] = 0xff; buf[40] = 0x7f; buf[39] = 0xff; buf[6] = 0x7f; buf[5] = 0xff; buf[4] = 0x7f; buf[3] = '\n'; buf[2] = '\0'; buf[1] = 0xff; buf[0] = '\0'; strtcpy(buf+4, "this is a string non-overflow test.?", 2); strtcpy(buf+4, "this is a string non-overflow test.?", 2); strtcpy(buf+4, "this is a string non-overflow test.?", 2); rval = strtcpy(buf+4, "this is a string non-overflow test.?", 2); assert(rval == -2); assert(buf[43] == '\n'); assert(buf[42] == '\0'); assert(buf[41] == 0xff); assert(buf[40] == 0x7f); assert(buf[39] == 0xff); assert(buf[6] == 0x7f); assert(buf[5] == 0x00); assert(buf[4] == 't'); assert(buf[3] == '\n'); assert(buf[2] == '\0'); assert(buf[1] == 0xff); assert(buf[0] == '\0'); } return iter*4; }
/* 对选择的列构建update语句,如果choose为空,全部列 ,返回尾部 */ char * SRM_mk_upd_col(SRM *srmp,char *DBOWN,const char *choose,char *stmt) { char *p,*p1; char col_name[49]; T_PkgType *tp; if(!srmp||!stmt) { return stmt; } p=SRM_mk_update(srmp,DBOWN,stmt); p=stpcpy(p,"SET "); p1=(char *)choose; if(p1 && *p1) do { if(!*p1) break; p1=stptok(skipblk(p1),col_name,sizeof(col_name),",|"); *p++ = '$'; p=stpcpy(stpcpy(stpcpy(p,col_name),"=:"),col_name); *p++ = ','; } while (*p1++); else for(tp=srmp->tp; tp->type>=0; tp++) { if(tp->type==CH_CLOB || tp->bindtype & NOINS) continue; p1=(char *)tp->name; p=stpcpy(stpcpy(strtcpy(p,&p1,' '),"=:"),plain_name(tp->name)); *p++ = ','; } *p=0; p[-1]=' '; return p; }
void ramdisk_setup() { if (!CONFIG_COREBOOT_FLASH || !CONFIG_FLASH_FLOPPY) return; // Find image. struct cbfs_file *file = cbfs_findprefix("floppyimg/", NULL); if (!file) return; u32 size = cbfs_datasize(file); dprintf(3, "Found floppy file %s of size %d\n", cbfs_filename(file), size); int ftype = find_floppy_type(size); if (ftype < 0) { dprintf(3, "No floppy type found for ramdisk size\n"); return; } // Allocate ram for image. void *pos = memalign_tmphigh(PAGE_SIZE, size); if (!pos) { dprintf(3, "Not enough memory for ramdisk\n"); return; } add_e820((u32)pos, size, E820_RESERVED); // Copy image into ram. cbfs_copyfile(file, pos, size); // Setup driver. dprintf(1, "Mapping CBFS floppy %s to addr %p\n", cbfs_filename(file), pos); struct drive_s *drive_g = addFloppy((u32)pos, ftype, DTYPE_RAMDISK); if (drive_g) strtcpy(drive_g->model, cbfs_filename(file), ARRAY_SIZE(drive_g->model)); }
/*** stxQueryFetch - get the next directory entry as an open object. ***/ void* stxQueryFetch(void* qy_v, pObject obj, int mode, pObjTrxTree* oxt) { pStxQuery qy = ((pStxQuery)(qy_v)); pStxData inf; /** Find a subgroup item **/ while(qy->ItemCnt < qy->Data->Data->nSubInf && stStructType(qy->Data->Data->SubInf[qy->ItemCnt]) != ST_T_SUBGROUP) qy->ItemCnt++; /** No more left? **/ if (qy->ItemCnt >= qy->Data->Data->nSubInf) return NULL; qy->CurInf = qy->Data->Data->SubInf[qy->ItemCnt]; /** Build the filename. **/ if (obj_internal_AddToPath(obj->Pathname, qy->CurInf->Name) < 0) return NULL; /** Alloc the structure **/ inf = (pStxData)nmMalloc(sizeof(StxData)); if (!inf) return NULL; strtcpy(inf->Pathname, obj->Pathname->Pathbuf, sizeof(inf->Pathname)); inf->Node = qy->Data->Node; inf->Data = qy->CurInf; inf->Node->OpenCnt++; inf->Obj = obj; inf->VecData = NULL; qy->ItemCnt++; return (void*)inf; }
/* * Append the name of the current file (to the message buffer). */ static void ap_filename() { if (ispipe) return; strtcpy(mp, current_file, &message[sizeof(message)] - mp); setmp(); }
/*** obfObfuscateDataSess() - looks up any appropriate rule in the rule *** file (if supplied), and calls obfObfuscateData accordingly. ***/ int obfObfuscateDataSess(pObfSession sess, pObjData srcval, pObjData dstval, int data_type, char* attrname, char* objname, char* type_name) { pObfRule rule; char which[8]; int rval; /** Find a rule **/ rule = obf_internal_FindRuleMatch(sess, srcval, data_type, attrname, objname, type_name); /** No obfuscation? **/ if (rule && rule->NoObfuscate) { switch(data_type) { case DATA_T_INTEGER: dstval->Integer = srcval->Integer; break; case DATA_T_STRING: case DATA_T_DATETIME: case DATA_T_MONEY: dstval->Generic = srcval->Generic; break; case DATA_T_DOUBLE: dstval->Double = srcval->Double; break; } return 0; } /** Attribute equivalency? **/ if (rule && rule->EquivAttr && rule->Param) { attrname = rule->Param; rule = obf_internal_FindRuleMatch(sess, srcval, data_type, attrname, objname, type_name); } /** Call the main obfuscation function **/ if (rule) { which[0] = '\0'; if (rule->HashKey) strcat(which,"K"); if (rule->HashAttr) strcat(which,"A"); if (rule->HashName) strcat(which,"N"); if (rule->HashType) strcat(which,"T"); if (rule->HashValue) strcat(which,"V"); rval = obfObfuscateData(srcval, dstval, data_type, attrname, objname, type_name, sess->Key, which, rule->Param, rule->Wordlist, rule->Catlist); } else { strtcpy(which, "KANTV", sizeof(which)); rval = obfObfuscateData(srcval, dstval, data_type, attrname, objname, type_name, sess->Key, which, NULL, NULL, NULL); } return rval; }
static char * addown_to_name(char *buf,char *DBOWN,const char *name) { char *p,*p1,*p2; p=buf; p1=(char *)name; do { p=strtcpy(p,&p1,*pre_tabname); if(*p1 && !strncmp(p1+1,pre_tabname+1,3)) { if(*DBOWN) { p2=DBOWN; p=strtcpy(p,&p2,0); p1+=3; } else p1+=4; } else if(*p1) { *p++=*p1++; *p=0; } } while(*p1) ; return p; }
/*** nht_internal_GetGeom() - deploy a snippet of javascript to the browser *** to fetch the window geometry and reload the application. ***/ int nht_internal_GetGeom(pObject target_obj, pFile output) { char bgnd[128]; char* ptr; int font_size = -1; char font_name[128]; /** Font sizes have an impact here **/ objGetAttrValue(target_obj, "font_size", DATA_T_INTEGER, POD(&font_size)); if (font_size < 5 || font_size > 100) font_size = -1; if (objGetAttrValue(target_obj, "font_name", DATA_T_STRING, POD(&ptr)) == 0 && ptr) strtcpy(font_name, ptr, sizeof(font_name)); else strcpy(font_name, ""); /** Do we have a bgcolor / background? **/ if (objGetAttrValue(target_obj, "bgcolor", DATA_T_STRING, POD(&ptr)) == 0) { snprintf(bgnd, sizeof(bgnd), "bgcolor='%.100s'", ptr); } else if (objGetAttrValue(target_obj, "background", DATA_T_STRING, POD(&ptr)) == 0) { snprintf(bgnd, sizeof(bgnd), "background='%.100s'", ptr); } else { strcpy(bgnd, "bgcolor='white'"); } /** Generate the snippet **/ fdQPrintf(output,"<html>\n" "<head>\n" " <meta http-equiv=\"Pragma\" CONTENT=\"no-cache\">\n" " <style type=\"text/css\">\n" " #l1 { POSITION:absolute; VISIBILITY: hidden; left:0px; top:0px; }\n" " #l2 { POSITION:absolute; VISIBILITY: hidden; left:0px; top:0px; }\n" " body { %[font-size:%POSpx; %]%[font-family:%STR&CSSVAL; %]}\n" " </style>\n" "<script type=\"text/javascript\" language=\"javascript\" src=\"/sys/js/startup.js\"></script>\n" "</head>\n" "<body %STR onload='startup();'>\n" " <img src='/sys/images/loading.gif'>\n" " <div id=\"l1\">x<br>x</div>\n" " <div id=\"l2\">xx</div>\n" "</body>\n" "</html>\n", font_size > 0, font_size, *font_name, font_name, bgnd); return 0; }
/*** strtcat() - truncating string concatenation *** *** Appends to dst, being sure to not overflow the given dstlen size. *** Returns number of bytes actually copied, including null terminator. *** If truncated, returns -(bytes copied). ***/ int strtcat(char* dst, const char* src, size_t dstlen) { if (__builtin_expect((!dstlen), 0)) return 0; /** Find end of current string **/ char* endptr = memchr(dst, '\0', dstlen); if (__builtin_expect((!endptr), 0)) return 0; if (__builtin_expect((endptr == dst+dstlen), 0)) return 0; /** Call strtcpy to copy the bytes and null-terminate it. **/ return strtcpy(endptr, src, dstlen - (endptr - dst)); }
char *mkset(char *str, T_PkgType *tp) { register T_PkgType *typ; char *cp,*p; if(!str || !tp) return str; if(tp->offset<0) set_offset(tp); cp=str; for(typ=tp;typ->type>=0;typ++) { if((typ->bindtype&NOINS) || typ->type == CH_CLOB || !strcmp(typ->name,"ROWID") || *typ->name==' ') continue; /* 提取真实列名 */ p=(char *)typ->name; cp=strtcpy(cp,&p,' '); *cp++ = ','; *cp=0; } *--cp=0; return cp; }
char *mkfield(char *field, T_PkgType *tp,const char *tabname) { T_PkgType *typ; char *cp; if(!field || !tp ) return field; if(tp->offset<0) set_offset(tp); if(!tabname || !*tabname) return (_mkfield(field,tp)); cp=field; for(typ=tp;typ->type>=0;typ++) { if(typ->bindtype & NOSELECT) continue; switch(typ->type) { case CH_MINUTS: case CH_DATE: case CH_JUL: case CH_TIME: case CH_USEC: if(typ->format) {//不能支持太复杂的日期表达式 char *p=(char *)typ->name; cp=stpcpy(stpcpy(cp,"TO_CHAR("),tabname); *cp++='.'; cp=stpcpy(ext_copy(stpcpy(strtcpy(cp,&p,' '),",\'"),typ->format),"\') "); if(*p==' ') cp=stpcpy(cp,++p); else cp=stpcpy(cp,typ->name); break; } default: cp=stpcpy(cp,tabname); *cp++='.'; cp=stpcpy(cp,typ->name); } *cp++=','; } *(--cp)=0; return cp; }
/*** httbtnRender - generate the HTML code for the page. ***/ int httbtnRender(pHtSession s, pWgtrNode tree, int z) { char* ptr; char name[64]; char text[64]; char fgcolor1[64]; char fgcolor2[64]; char bgstyle[128]; char disable_color[64]; int x,y,w,h; int id, i; int is_ts = 1; int is_enabled = 1; pExpression code; int box_offset; int clip_offset; int border_radius; char border_style[32]; char border_color[64]; char image_position[16]; /* top, left, right, bottom */ char image[OBJSYS_MAX_PATH]; char h_align[16]; int image_width=0, image_height=0, image_margin=0; if(!s->Capabilities.Dom0NS && !s->Capabilities.Dom0IE && !(s->Capabilities.Dom1HTML && s->Capabilities.Dom2CSS)) { mssError(1,"HTTBTN","Netscape DOM or (W3C DOM1 HTML and W3C DOM2 CSS) support required"); return -1; } /** Get an id for this. **/ id = (HTTBTN.idcnt++); /** Get x,y,w,h of this object **/ if (wgtrGetPropertyValue(tree,"x",DATA_T_INTEGER,POD(&x)) != 0) { mssError(1,"HTTBTN","TextButton widget must have an 'x' property"); return -1; } if (wgtrGetPropertyValue(tree,"y",DATA_T_INTEGER,POD(&y)) != 0) { mssError(1,"HTTBTN","TextButton widget must have a 'y' property"); return -1; } if (wgtrGetPropertyValue(tree,"width",DATA_T_INTEGER,POD(&w)) != 0) { mssError(1,"HTTBTN","TextButton widget must have a 'width' property"); return -1; } if (wgtrGetPropertyValue(tree,"height",DATA_T_INTEGER,POD(&h)) != 0) h = -1; if (wgtrGetPropertyType(tree,"enabled") == DATA_T_STRING && wgtrGetPropertyValue(tree,"enabled",DATA_T_STRING,POD(&ptr)) == 0 && ptr) { if (!strcasecmp(ptr,"false") || !strcasecmp(ptr,"no")) is_enabled = 0; } /** Border radius, color, and style. For style, we only support outset, ** solid, and none here. **/ if (wgtrGetPropertyValue(tree,"border_radius",DATA_T_INTEGER,POD(&border_radius)) != 0) border_radius=0; if (wgtrGetPropertyValue(tree,"border_color",DATA_T_STRING,POD(&ptr)) != 0) strcpy(border_color, "#c0c0c0"); else strtcpy(border_color, ptr, sizeof(border_color)); if (wgtrGetPropertyValue(tree,"border_style",DATA_T_STRING,POD(&ptr)) != 0 || (strcmp(ptr,"outset") && strcmp(ptr,"solid") && strcmp(ptr,"none"))) strcpy(border_style, "outset"); else strtcpy(border_style, ptr, sizeof(border_style)); /** Alignment **/ if (wgtrGetPropertyValue(tree,"align",DATA_T_STRING,POD(&ptr)) == 0 && (!strcmp(ptr,"left") || !strcmp(ptr,"right") || !strcmp(ptr,"center"))) strtcpy(h_align, ptr, sizeof(h_align)); else strcpy(h_align, "center"); /** Image location **/ if (wgtrGetPropertyValue(tree,"image_position",DATA_T_STRING,POD(&ptr)) != 0 || (strcmp(ptr,"top") && strcmp(ptr,"right") && strcmp(ptr,"bottom") && strcmp(ptr, "left"))) strcpy(image_position, "top"); else strtcpy(image_position, ptr, sizeof(image_position)); /** Image source **/ if (wgtrGetPropertyValue(tree,"image",DATA_T_STRING,POD(&ptr)) != 0) strcpy(image, ""); else strtcpy(image, ptr, sizeof(image)); /** Image sizing **/ if (wgtrGetPropertyValue(tree,"image_width",DATA_T_INTEGER, POD(&image_width)) != 0) image_width = 0; if (wgtrGetPropertyValue(tree,"image_height",DATA_T_INTEGER, POD(&image_height)) != 0) image_height = 0; if (wgtrGetPropertyValue(tree,"image_margin",DATA_T_INTEGER, POD(&image_margin)) != 0) image_margin = 0; /** Get name **/ if (wgtrGetPropertyValue(tree,"name",DATA_T_STRING,POD(&ptr)) != 0) return -1; strtcpy(name,ptr,sizeof(name)); /** box adjustment... arrgh **/ if (s->Capabilities.CSSBox) box_offset = 1; else box_offset = 0; clip_offset = s->Capabilities.CSSClip?1:0; /** User requesting expression for enabled? **/ if (wgtrGetPropertyType(tree,"enabled") == DATA_T_CODE) { wgtrGetPropertyValue(tree,"enabled",DATA_T_CODE,POD(&code)); is_enabled = 0; htrAddExpression(s, name, "enabled", code); } /** Threestate button or twostate? **/ if (wgtrGetPropertyValue(tree,"tristate",DATA_T_STRING,POD(&ptr)) == 0 && !strcmp(ptr,"no")) is_ts = 0; /** Get normal, point, and click images **/ ptr = "-"; if (!htrCheckAddExpression(s, tree, name, "text") && wgtrGetPropertyValue(tree,"text",DATA_T_STRING,POD(&ptr)) != 0) { mssError(1,"HTTBTN","TextButton widget must have a 'text' property"); return -1; } strtcpy(text,ptr,sizeof(text)); /** Get fgnd colors 1,2, and background color **/ htrGetBackground(tree, NULL, 1, bgstyle, sizeof(bgstyle)); if (wgtrGetPropertyValue(tree,"fgcolor1",DATA_T_STRING,POD(&ptr)) == 0) strtcpy(fgcolor1,ptr,sizeof(fgcolor1)); else strcpy(fgcolor1,"white"); if (wgtrGetPropertyValue(tree,"fgcolor2",DATA_T_STRING,POD(&ptr)) == 0) strtcpy(fgcolor2,ptr,sizeof(fgcolor2)); else strcpy(fgcolor2,"black"); if (wgtrGetPropertyValue(tree,"disable_color",DATA_T_STRING,POD(&ptr)) == 0) strtcpy(disable_color,ptr,sizeof(disable_color)); else strcpy(disable_color,"#808080"); htrAddScriptGlobal(s, "tb_current", "null", 0); /** DOM Linkages **/ htrAddWgtrObjLinkage_va(s, tree, "tb%POSpane",id); /** Include the javascript code for the textbutton **/ htrAddScriptInclude(s, "/sys/js/htdrv_textbutton.js", 0); htrAddScriptInclude(s, "/sys/js/ht_utils_layers.js", 0); /** Initial CSS styles **/ htrAddStylesheetItem_va(s,"\t#tb%POSpane { POSITION:absolute; VISIBILITY:inherit; LEFT:%INTpx; TOP:%INTpx; %[HEIGHT:%POSpx; %]WIDTH:%POSpx; Z-INDEX:%POS; OVERFLOW:hidden; display:table; }\n", id, x, y, h>=0, h-1-2*box_offset, w-1-2*box_offset, z ); htrAddStylesheetItem_va(s, "\t#tb%POSpane .cell { height:100%%; width:100%%; vertical-align:middle; display:table-cell; padding:1px; font-weight:bold; cursor:default; text-align:%STR; border-width:1px; border-style:%STR&CSSVAL; border-color:%STR&CSSVAL; border-radius:%INTpx; color:%STR&CSSVAL; %[text-shadow:1px 1px %STR&CSSVAL; %]%STR }\n", /* clipping no longer needed: 0, w-1-2*box_offset+2*clip_offset, h-1-2*box_offset+2*clip_offset, 0, */ id, h_align, border_style, border_color, border_radius, is_enabled?fgcolor1:disable_color, is_enabled, fgcolor2, bgstyle ); /** CSS for image on the button **/ if (image[0] && (image_width || image_height || image_margin)) { htrAddStylesheetItem_va(s, "\t#tb%POSpane img { %[height:%POSpx; %]%[width:%POSpx; %]%[margin:%POSpx;%] }\n", id, image_height, image_height, image_width, image_width, image_margin, image_margin); } #if 00 if(h >=0 ) { htrAddStylesheetItem_va(s,"\t#tb%POSpane { POSITION:absolute; VISIBILITY:inherit; LEFT:%INTpx; TOP:%INTpx; HEIGHT:%POSpx; WIDTH:%POSpx; Z-INDEX:%POS; OVERFLOW:hidden; clip:rect(%INTpx %INTpx %INTpx %INTpx)}\n", id, x, y, h-1-2*box_offset, w-1-2*box_offset, z, 0, w-1-2*box_offset+2*clip_offset, h-1-2*box_offset+2*clip_offset, 0); } else { htrAddStylesheetItem_va(s,"\t#tb%POSpane { POSITION:absolute; VISIBILITY:inherit; LEFT:%INTpx; TOP:%INTpx; WIDTH:%POSpx; Z-INDEX:%POS; OVERFLOW:hidden; clip:rect(%INTpx %INTpx auto %INTpx)}\n",id,x,y,w-1-2*box_offset,z,0,w-1-2*box_offset+2*clip_offset,0); } htrAddStylesheetItem_va(s,"\t#tb%POSpane { cursor:default; text-align: center; %STR border-width: 1px; border-style: solid; border-color: white gray gray white; border-radius: %INTpx; }\n",id,bgstyle, border_radius); if (is_enabled) htrAddStylesheetItem_va(s,"\t#tb%POSspan { color:%STR&CSSVAL; text-shadow:1px 1px %STR&CSSVAL; }\n", id, fgcolor1, fgcolor2); else htrAddStylesheetItem_va(s,"\t#tb%POSspan { color:%STR&CSSVAL; }\n", id, disable_color); #endif //htrAddBodyItem_va(s,"<DIV ID=\"tb%POSpane\"><center><table cellspacing=0 cellpadding=1 border=0><tr><td height=%POS valign=middle align=center><span id=\"tb%POSspan\"><b>%STR&HTE</b></span></td></tr></table></center>\n", id, h-3, id, text); //htrAddBodyItem(s, "</DIV>"); /** We need two DIVs here because of a long-outstanding Firefox bug :( **/ htrAddBodyItem_va(s,"<div id=\"tb%POSpane\"><div class=\"cell\">%[<img border=\"0\" src=\"%STR&HTE\"/><br>%]%[<img border=\"0\" src=\"%STR&HTE\" style=\"vertical-align:middle;\"/>%]<span>%STR&HTE</span>%[<img border=\"0\" src=\"%STR&HTE\" style=\"vertical-align:middle;\"/>%]%[<br><img border=\"0\" src=\"%STR&HTE\"/>%]</div></div>", id, image[0] && !strcmp(image_position, "top"), image, image[0] && !strcmp(image_position, "left"), image, text, image[0] && !strcmp(image_position, "right"), image, image[0] && !strcmp(image_position, "bottom"), image ); /** Script initialization call. **/ //htrAddScriptInit_va(s, " tb_init({layer:wgtrGetNodeRef(ns,'%STR&SYM'), span:document.getElementById(\"tb%POSspan\"), ena:%INT, c1:\"%STR&JSSTR\", c2:\"%STR&JSSTR\", dc1:\"%STR&JSSTR\", top:null, bottom:null, right:null, left:null, width:%INT, height:%INT, tristate:%INT, name:\"%STR&SYM\", text:'%STR&JSSTR'});\n", //name, id, is_enabled, fgcolor1, fgcolor2, disable_color, w, h, is_ts, name, text); htrAddScriptInit_va(s, " tb_init({layer:wgtrGetNodeRef(ns,'%STR&SYM'), ena:%INT, c1:\"%STR&JSSTR\", c2:\"%STR&JSSTR\", dc1:\"%STR&JSSTR\", top:null, bottom:null, right:null, left:null, width:%INT, height:%INT, tristate:%INT, name:\"%STR&SYM\", text:'%STR&JSSTR'});\n", name, is_enabled, fgcolor1, fgcolor2, disable_color, w, h, is_ts, name, text); /** Add the event handling scripts **/ htrAddEventHandlerFunction(s, "document", "MOUSEDOWN", "tb", "tb_mousedown"); htrAddEventHandlerFunction(s, "document", "MOUSEUP", "tb", "tb_mouseup"); htrAddEventHandlerFunction(s, "document", "MOUSEOVER", "tb", "tb_mouseover"); htrAddEventHandlerFunction(s, "document", "MOUSEOUT", "tb", "tb_mouseout"); htrAddEventHandlerFunction(s, "document", "MOUSEMOVE", "tb", "tb_mousemove"); /** IE handles dblclick strangely **/ if (s->Capabilities.Dom0IE) htrAddEventHandlerFunction(s, "document", "DBLCLICK", "tb", "tb_dblclick"); /** Check for more sub-widgets within the textbutton. **/ for (i=0;i<xaCount(&(tree->Children));i++) htrRenderWidget(s, xaGetItem(&(tree->Children), i), z+3); return 0; }
/*** obfOpenSession() - opens a new "session" for obfuscating data. This *** opens up a rule file (through objOpen, i.e., through the OSML), and *** sets a key value to use for future obfObfuscateDataSess calls. ***/ pObfSession obfOpenSession(pObjSession objsess, char* rule_file_osml_path, char* key) { pObfSession s = NULL; unsigned char binkey[OBF_KEY_SIZE]; char* hexdigit = "0123456789abcdef"; int i; pObject rules_obj = NULL; pLxSession lexer = NULL; pObfRule rule, *ruletail; int t; /** Allocate the session and set it up **/ s = (pObfSession)nmMalloc(sizeof(ObfSession)); if (!s) goto error; memset(s, 0, sizeof(ObfSession)); if (rule_file_osml_path) strtcpy(s->RuleFilePath, rule_file_osml_path, sizeof(s->RuleFilePath)); if (key && *key) { /** Use the key the user provided **/ s->Key = nmSysStrdup(key); } else { /** Generate a random key **/ s->Key = nmSysMalloc(OBF_HEXKEYBUF_SIZE); /* 64 bit hexstring */ if (!s->Key) goto error; if (cxssGenerateKey(binkey, sizeof(binkey)) < 0) goto error; for(i=0;i<OBF_KEY_SIZE;i++) { s->Key[i*2] = hexdigit[binkey[i] >> 4]; s->Key[i*2 + 1] = hexdigit[binkey[i] & 0x0f]; } s->Key[OBF_HEXKEYBUF_SIZE - 1] = '\0'; } /** Load the rules **/ if (*s->RuleFilePath) { /** Open the object and start a lexer session on it **/ rules_obj = objOpen(objsess, s->RuleFilePath, O_RDONLY, 0600, "system/file"); if (!rules_obj) goto error; lexer = mlxGenericSession(rules_obj, objRead, MLX_F_IFSONLY | MLX_F_EOL | MLX_F_EOF | MLX_F_POUNDCOMM); if (!lexer) goto error; ruletail = &(s->RuleList); /** Read in the rules **/ while((t = mlxNextToken(lexer)) != MLX_TOK_EOF && t != MLX_TOK_ERROR) { /** blank line or line with just a comment? **/ if (t == MLX_TOK_EOL) continue; if (t != MLX_TOK_STRING) { mssError(1,"OBF","Could not parse obfuscation rule: expected rule string"); goto error; } /** Create a new rule **/ rule = obf_internal_ParseRule(objsess, lexer); if (!rule) { mssError(1,"OBF","Could not parse obfuscation rule"); goto error; } /** Add to the rule list **/ *ruletail = rule; ruletail = &(rule->Next); } mlxCloseSession(lexer); lexer = NULL; objClose(rules_obj); rules_obj = NULL; } return s; error: if (lexer) mlxCloseSession(lexer); if (rules_obj) objClose(rules_obj); if (s) { if (s->Key) nmSysFree(s->Key); nmFree(s, sizeof(ObfSession)); } return NULL; }
void start(void* v) { char enc_pass[64]; char salt[MSS_SALT_SIZE + 1]; char passwd_line[128]; XString passwd_contents; pFile passwd_file; char buf[256]; int len; int offset; int pos; int uname_len; int found_user; size_t found_len; char* nlptr; char* ptr; cxssInitialize(); /** No file specified? **/ if (!CXPASSWD.PasswdFile[0]) { puts("no passwd file specified (use option -f)."); exit(1); } /** User asked us to read password from stdin? **/ if (CXPASSWD.ReadStdin) { fgets(CXPASSWD.Password, sizeof(CXPASSWD.Password), stdin); if (strchr(CXPASSWD.Password, '\n')) { *strchr(CXPASSWD.Password, '\n') = '\0'; } } /** Now get username and/or password if not supplied on command line **/ if (!CXPASSWD.UserName[0]) { ptr = readline("Username: "******"Password: "******"could not generate random bytes for password salt."); exit(1); } /** Generate encrypted credential **/ if (mssGenCred(salt, MSS_SALT_SIZE, CXPASSWD.Password, enc_pass, sizeof(enc_pass)) < 0) { puts("could not generate encrypted password."); exit(1); } /** Generate our password file line **/ snprintf(passwd_line, sizeof(passwd_line), "%s:%s\n", CXPASSWD.UserName, enc_pass); /** Open the password file **/ passwd_file = fdOpen(CXPASSWD.PasswdFile, O_RDWR | O_CREAT, 0600); if (!passwd_file) { puts("could not open passwd file."); exit(1); } /** Read it into the xstring **/ xsInit(&passwd_contents); while((len = fdRead(passwd_file, buf, sizeof(buf), 0, 0)) > 0) { xsConcatenate(&passwd_contents, buf, len); } fdClose(passwd_file, 0); /** Do we already have this user? **/ uname_len = strlen(CXPASSWD.UserName); offset = 0; found_user = -1; while((pos = xsFind(&passwd_contents, CXPASSWD.UserName, uname_len, offset)) >= 0) { if ((pos == 0 || xsString(&passwd_contents)[pos-1] == '\n') && xsString(&passwd_contents)[pos+uname_len] == ':') { /** Found it **/ found_user = pos; found_len = strlen(xsString(&passwd_contents)+pos); if ((nlptr = strchr(xsString(&passwd_contents)+pos, '\n')) != NULL) found_len = (nlptr - (xsString(&passwd_contents)+pos)) + 1; break; } offset = pos+1; } /** Replace if found, otherwise add the new user **/ if (found_user >= 0) xsSubst(&passwd_contents, found_user, found_len, passwd_line, strlen(passwd_line)); else xsConcatenate(&passwd_contents, passwd_line, strlen(passwd_line)); /** Rewrite the entire file **/ passwd_file = fdOpen(CXPASSWD.PasswdFile, O_RDWR | O_CREAT | O_TRUNC, 0600); if (!passwd_file) { puts("could not open password file to write to it."); exit(1); } if (fdWrite(passwd_file, xsString(&passwd_contents), strlen(xsString(&passwd_contents)), 0, FD_U_SEEK | FD_U_PACKET) != strlen(xsString(&passwd_contents))) { puts("could not re-write new password file."); exit(1); } /** Close the file **/ fdClose(passwd_file, 0); exit(0); }
/*** shl_internal_Launch -- launches the subprocess and sets up the communication ***/ int shl_internal_Launch(pShlData inf) { char tty_name[32]; int pty; int i; int maxfiles; gid_t gidlist[1]; for(i=0;i<xaCount(&inf->envList);i++) { pEnvVar pEV; char* name; char* p; name=(char*)xaGetItem(&inf->envList,i); pEV=(pEnvVar)xhLookup(&inf->envHash,name); if(pEV) { int len = strlen(name)+2+(pEV->value?strlen(pEV->value):0); p = (char*)nmSysMalloc(len); snprintf(p,len,"%s=%s",name,pEV->value?pEV->value:""); p[len-1]='\0'; xaAddItem(&inf->envArray,p); } } xaAddItem(&inf->envArray,NULL); if(SHELL_DEBUG & SHELL_DEBUG_LAUNCH) { char **ptr; int i=0; printf("%s(%p)\n",__FUNCTION__,inf); printf("program: %s\n",inf->program); ptr=(char**)(inf->argArray.Items); do { printf("arg: %p: %s\n",ptr,*ptr); } while(*(ptr++)); ptr=(char**)(inf->envArray.Items); do { printf("env: %p: %s\n",ptr,*ptr); } while(*(ptr++)); } pty=getpt(); if(pty<0) { mssError(0,"SHL","getpy() failed"); inf->shell_pid=0; return -1; } if(grantpt(pty)<0 || unlockpt(pty)<0) { mssError(0,"SHL","granpt() or unlockpt() failed"); inf->shell_pid=0; return -1; } if(SHELL_DEBUG & SHELL_DEBUG_OPEN) printf("shell got tty: %s\n",(const char*)ptsname(pty)); strtcpy(tty_name,(const char*)ptsname(pty),sizeof(tty_name)); inf->shell_pid=fork(); if(inf->shell_pid < 0) { mssErrorErrno(1,"SHL","Unable to fork"); inf->shell_pid=0; return -1; } if(inf->shell_pid==0) { int fd; /** we're in the child process -- disable MTask context switches to be safe **/ thLock(); /** child -- shell **/ if(SHELL_DEBUG & SHELL_DEBUG_FORK) printf("in child\n"); /** security issue: when centrallix runs as root with system ** authentication, the threads run with ruid=root, euid=user, ** and we need to get rid of the ruid=root here so that the ** command's privs are more appropriate. Same for group id. **/ setgroups(0, gidlist); if (getuid() != geteuid()) { if (setreuid(geteuid(),-1) < 0) { /** Rats! we couldn't do it! **/ mssError(1,"SHL","Could not drop privileges!"); _exit(1); } } if (getgid() != getegid()) { if (setregid(getegid(),-1) < 0) { /** Rats! we couldn't do it! **/ mssError(1,"SHL","Could not drop group privileges!"); _exit(1); } } /** close all open fds (except for 0-2 -- std{in,out,err}) **/ maxfiles = sysconf(_SC_OPEN_MAX); if (maxfiles <= 0) { printf("Warning: sysconf(_SC_OPEN_MAX) returned <= 0; using maxfiles=2048.\n"); maxfiles = 2048; } for(fd=3;fd<maxfiles;fd++) close(fd); /** start a new process session and open the terminal **/ setsid(); fd = open(tty_name,O_RDWR); /** switch to terminal as stdout **/ dup2(fd,0); /** switch to terminal as stdin **/ dup2(fd,1); /** switch to terminal as stderr **/ dup2(fd,2); /** close old copy of FD **/ if (fd > 2) close(fd); /** make the exec() call **/ execve(inf->program,(char**)(inf->argArray.Items),(char**)(inf->envArray.Items)); /** if exec() is successfull, this is never reached **/ warn("execve() failed"); { /** execve shouldn't fail -- dump the args for debugging **/ char **ptr; int i=0; printf("program: %s\n",inf->program); ptr=(char**)(inf->argArray.Items); do { printf("arg: %p: %s\n",ptr,*ptr); } while(*(ptr++)); ptr=(char**)(inf->envArray.Items); do { printf("env: %p: %s\n",ptr,*ptr); } while(*(ptr++)); } _exit(1); } /** parent -- centrallix **/ if(SHELL_DEBUG & SHELL_DEBUG_FORK) printf("still in parent :)\n"); /** open up the terminal that we'll use for comm with the child process **/ inf->shell_fd=fdOpenFD(pty,O_RDWR); return 0; }
/* htddRender - generate the HTML code for the page. */ int htddRender(pHtSession s, pWgtrNode tree, int z) { char bgstr[HT_SBUF_SIZE]; char hilight[HT_SBUF_SIZE]; char string[HT_SBUF_SIZE]; char fieldname[30]; char form[64]; char osrc[64]; char name[64]; char *ptr; char *sql; char *str; char *attr; int type, rval, mode, flag=0; int x,y,w,h; int id, i; int num_disp; int query_multiselect; int invalid_select_default; int pop_w; ObjData od; XString xs; pObjQuery qy; pObject qy_obj; pWgtrNode subtree; if(!s->Capabilities.Dom0NS && !s->Capabilities.Dom1HTML) { mssError(1,"HTDD","Netscape or W3C DOM support required"); return -1; } /** Get an id for this. **/ id = (HTDD.idcnt++); /** Get x,y of this object **/ if (wgtrGetPropertyValue(tree,"x",DATA_T_INTEGER,POD(&x)) != 0) x=0; if (wgtrGetPropertyValue(tree,"y",DATA_T_INTEGER,POD(&y)) != 0) y=0; if (wgtrGetPropertyValue(tree,"height",DATA_T_INTEGER,POD(&h)) != 0) h=0; if (h < s->ClientInfo->ParagraphHeight+2) h = s->ClientInfo->ParagraphHeight+2; if (wgtrGetPropertyValue(tree,"width",DATA_T_INTEGER,POD(&w)) != 0) { mssError(1,"HTDD","Drop Down widget must have a 'width' property"); return -1; } pop_w = w; /** Width of popup dropdown list **/ wgtrGetPropertyValue(tree,"popup_width", DATA_T_INTEGER, POD(&pop_w)); query_multiselect = htrGetBoolean(tree, "query_multiselect", 0); invalid_select_default = htrGetBoolean(tree, "invalid_select_default", 0); if (wgtrGetPropertyValue(tree,"numdisplay",DATA_T_INTEGER,POD(&num_disp)) != 0) num_disp=3; if (wgtrGetPropertyValue(tree,"hilight",DATA_T_STRING,POD(&ptr)) == 0) { strtcpy(hilight,ptr,sizeof(hilight)); } else { mssError(1,"HTDD","Drop Down widget must have a 'hilight' property"); return -1; } if (wgtrGetPropertyValue(tree,"bgcolor",DATA_T_STRING,POD(&ptr)) == 0) { strtcpy(bgstr,ptr,sizeof(bgstr)); } else { mssError(1,"HTDD","Drop Down widget must have a 'bgcolor' property"); return -1; } if (wgtrGetPropertyValue(tree,"fieldname",DATA_T_STRING,POD(&ptr)) == 0) { strtcpy(fieldname,ptr,sizeof(fieldname)); } else { fieldname[0]='\0'; } if (wgtrGetPropertyValue(tree,"form",DATA_T_STRING,POD(&ptr)) == 0) strtcpy(form,ptr,sizeof(form)); else form[0]='\0'; if (wgtrGetPropertyValue(tree,"objectsource",DATA_T_STRING,POD(&ptr)) == 0) strtcpy(osrc,ptr,sizeof(osrc)); else osrc[0]='\0'; /** Get name **/ if (wgtrGetPropertyValue(tree,"name",DATA_T_STRING,POD(&ptr)) != 0) return -1; strtcpy(name,ptr,sizeof(name)); /** Ok, write the style header items. **/ htrAddStylesheetItem_va(s,"\t#dd%POSbtn { OVERFLOW:hidden; POSITION:absolute; VISIBILITY:inherit; LEFT:%INTpx; TOP:%INTpx; HEIGHT:%POSpx; WIDTH:%POSpx; Z-INDEX:%POS; cursor:default; background-color: %STR&CSSVAL; }\n",id,x,y,h,w,z,bgstr); htrAddStylesheetItem_va(s,"\t#dd%POScon1 { OVERFLOW:hidden; POSITION:absolute; VISIBILITY:inherit; LEFT:1px; TOP:1px; WIDTH:1024px; HEIGHT:%POSpx; Z-INDEX:%POS; }\n",id,h-2,z+1); htrAddStylesheetItem_va(s,"\t#dd%POScon2 { OVERFLOW:hidden; POSITION:absolute; VISIBILITY:hidden; LEFT:1px; TOP:1px; WIDTH:1024px; HEIGHT:%POSpx; Z-INDEX:%POS; }\n",id,h-2,z+1); htrAddScriptGlobal(s, "dd_current", "null", 0); htrAddScriptGlobal(s, "dd_lastkey", "null", 0); htrAddScriptGlobal(s, "dd_target_img", "null", 0); htrAddScriptGlobal(s, "dd_thum_y","0",0); htrAddScriptGlobal(s, "dd_timeout","null",0); htrAddScriptGlobal(s, "dd_click_x","0",0); htrAddScriptGlobal(s, "dd_click_y","0",0); htrAddScriptGlobal(s, "dd_incr","0",0); htrAddScriptGlobal(s, "dd_cur_mainlayer","null",0); htrAddWgtrObjLinkage_va(s, tree, "dd%POSbtn", id); htrAddScriptInclude(s, "/sys/js/ht_utils_layers.js", 0); htrAddScriptInclude(s, "/sys/js/ht_utils_string.js", 0); htrAddScriptInclude(s, "/sys/js/ht_utils_hints.js", 0); htrAddScriptInclude(s, "/sys/js/htdrv_dropdown.js", 0); htrAddEventHandlerFunction(s, "document","MOUSEMOVE", "dd", "dd_mousemove"); htrAddEventHandlerFunction(s, "document","MOUSEOVER", "dd", "dd_mouseover"); htrAddEventHandlerFunction(s, "document","MOUSEUP", "dd", "dd_mouseup"); htrAddEventHandlerFunction(s, "document","MOUSEDOWN", "dd", "dd_mousedown"); htrAddEventHandlerFunction(s, "document","MOUSEOUT", "dd", "dd_mouseout"); if (s->Capabilities.Dom1HTML) htrAddEventHandlerFunction(s, "document", "CONTEXTMENU", "dd", "dd_contextmenu"); /** Get the mode (default to 1, dynamicpage) **/ mode = 0; if (wgtrGetPropertyValue(tree,"mode",DATA_T_STRING,POD(&ptr)) == 0) { if (!strcmp(ptr,"static")) mode = 0; else if (!strcmp(ptr,"dynamic_server")) mode = 1; else if (!strcmp(ptr,"dynamic")) mode = 2; else if (!strcmp(ptr,"dynamic_client")) mode = 2; else if (!strcmp(ptr,"objectsource")) mode = 3; else { mssError(1,"HTDD","Dropdown widget has not specified a valid mode."); return -1; } } sql = 0; if (wgtrGetPropertyValue(tree,"sql",DATA_T_STRING,POD(&sql)) != 0 && mode != 0 && mode != 3) { mssError(1, "HTDD", "SQL parameter was not specified for dropdown widget"); return -1; } /** Script initialization call. **/ htrAddScriptInit_va(s," dd_init({layer:wgtrGetNodeRef(ns,\"%STR&SYM\"), c1:htr_subel(wgtrGetNodeRef(ns,\"%STR&SYM\"), \"dd%POScon1\"), c2:htr_subel(wgtrGetNodeRef(ns,\"%STR&SYM\"), \"dd%POScon2\"), background:'%STR&JSSTR', highlight:'%STR&JSSTR', fieldname:'%STR&JSSTR', numDisplay:%INT, mode:%INT, sql:'%STR&JSSTR', width:%INT, height:%INT, form:'%STR&JSSTR', osrc:'%STR&JSSTR', qms:%INT, ivs:%INT, popup_width:%INT});\n", name, name, id, name, id, bgstr, hilight, fieldname, num_disp, mode, sql?sql:"", w, h, form, osrc, query_multiselect, invalid_select_default, pop_w); /** HTML body <DIV> element for the layers. **/ htrAddBodyItem_va(s,"<DIV ID=\"dd%POSbtn\">\n", id); htrAddBodyItem_va(s,"<TABLE width=%POS cellspacing=0 cellpadding=0 border=0>\n",w); htrAddBodyItem(s, " <TR><TD><IMG SRC=/sys/images/white_1x1.png></TD>\n"); htrAddBodyItem_va(s," <TD><IMG SRC=/sys/images/white_1x1.png height=1 width=%POS></TD>\n",w-2); htrAddBodyItem(s, " <TD><IMG SRC=/sys/images/white_1x1.png></TD></TR>\n"); htrAddBodyItem_va(s," <TR><TD><IMG SRC=/sys/images/white_1x1.png height=%POS width=1></TD>\n",h-2); htrAddBodyItem(s, " <TD align=right valign=middle><IMG SRC=/sys/images/ico15b.gif></TD>\n"); htrAddBodyItem_va(s," <TD><IMG SRC=/sys/images/dkgrey_1x1.png height=%POS width=1></TD></TR>\n",h-2); htrAddBodyItem(s, " <TR><TD><IMG SRC=/sys/images/dkgrey_1x1.png></TD>\n"); htrAddBodyItem_va(s," <TD><IMG SRC=/sys/images/dkgrey_1x1.png height=1 width=%POS></TD>\n",w-2); htrAddBodyItem(s, " <TD><IMG SRC=/sys/images/dkgrey_1x1.png></TD></TR>\n"); htrAddBodyItem(s, "</TABLE>\n"); htrAddBodyItem_va(s,"<DIV ID=\"dd%POScon1\"></DIV>\n",id); htrAddBodyItem_va(s,"<DIV ID=\"dd%POScon2\"></DIV>\n",id); htrAddBodyItem(s, "</DIV>\n"); /* Read and initialize the dropdown items */ if (mode == 1) { /** The result set from this SQL query can take two forms: positional or named. ** For Positional, the params are: label, value, selected, group, hidden. ** For Named, the above names can appear in any order. ** label and value are required. **/ if ((qy = objMultiQuery(s->ObjSession, sql, NULL, 0))) { flag=0; htrAddScriptInit_va(s," dd_add_items(wgtrGetNodeRef(ns,\"%STR&SYM\"), [",name); while ((qy_obj = objQueryFetch(qy, O_RDONLY))) { // Label attr = objGetFirstAttr(qy_obj); if (!attr) { objClose(qy_obj); objQueryClose(qy); mssError(1, "HTDD", "SQL query must have at least two attributes: label and value."); return -1; } type = objGetAttrType(qy_obj, attr); rval = objGetAttrValue(qy_obj, attr, type,&od); // Check if anything was returned if(rval != 0){ objClose(qy_obj); continue; } if (type == DATA_T_INTEGER || type == DATA_T_DOUBLE) { str = objDataToStringTmp(type, (void*)(&od), DATA_F_QUOTED); } else { str = objDataToStringTmp(type, (void*)(od.String), DATA_F_QUOTED); } if (flag) htrAddScriptInit(s,","); htrAddScriptInit_va(s,"{wname:null, label:%STR,",str); // Value attr = objGetNextAttr(qy_obj); if (!attr) { objClose(qy_obj); objQueryClose(qy); mssError(1, "HTDD", "SQL query must have at least two attributes: label and value."); return -1; } type = objGetAttrType(qy_obj, attr); rval = objGetAttrValue(qy_obj, attr, type,&od); if (type == DATA_T_INTEGER || type == DATA_T_DOUBLE) { str = objDataToStringTmp(type, (void*)(&od), DATA_F_QUOTED); } else { str = objDataToStringTmp(type, (void*)(od.String), DATA_F_QUOTED); } htrAddScriptInit_va(s,"value:%STR", str); /** is selected **/ attr = objGetNextAttr(qy_obj); if (attr) { type = objGetAttrType(qy_obj, attr); rval = objGetAttrValue(qy_obj, attr, type, &od); htrAddScriptInit_va(s, ",sel:%INT", type == DATA_T_INTEGER && rval == 0 && od.Integer != 0); /** grouping **/ attr = objGetNextAttr(qy_obj); if (attr) { type = objGetAttrType(qy_obj, attr); rval = objGetAttrValue(qy_obj, attr, type, &od); if (rval == 0 && type == DATA_T_INTEGER) htrAddScriptInit_va(s, ",grp:%INT", od.Integer); else if (rval == 0 && type == DATA_T_STRING) htrAddScriptInit_va(s, ",grp:\"%STR&JSSTR\"", od.String); /** hidden **/ attr = objGetNextAttr(qy_obj); if (attr) { type = objGetAttrType(qy_obj, attr); rval = objGetAttrValue(qy_obj, attr, type, &od); htrAddScriptInit_va(s, ",hide:%INT}", type == DATA_T_INTEGER && rval == 0 && od.Integer != 0); } else { htrAddScriptInit(s, "}"); } } else { htrAddScriptInit(s, "}"); } } else { htrAddScriptInit(s, "}"); } objClose(qy_obj); flag=1; } htrAddScriptInit(s,"]);\n"); objQueryClose(qy); } } else if(mode==3) { /* get objects from form */ } flag=0; for (i=0;i<xaCount(&(tree->Children));i++) { subtree = xaGetItem(&(tree->Children), i); if (!strcmp(subtree->Type, "widget/dropdownitem")) subtree->RenderFlags |= HT_WGTF_NOOBJECT; if (!strcmp(subtree->Type,"widget/dropdownitem") && mode == 0) { if (wgtrGetPropertyValue(subtree,"label",DATA_T_STRING,POD(&ptr)) != 0) { mssError(1,"HTDD","Drop Down widget must have a 'width' property"); return -1; } strtcpy(string, ptr, sizeof(string)); if (flag) { xsConcatenate(&xs, ",", 1); } else { xsInit(&xs); xsConcatQPrintf(&xs, " dd_add_items(wgtrGetNodeRef(ns,\"%STR&SYM\"), [", name); flag=1; } wgtrGetPropertyValue(subtree,"name",DATA_T_STRING,POD(&ptr)); xsConcatQPrintf(&xs,"{wname:'%STR&SYM', label:'%STR&JSSTR',", ptr, string); if (htrGetBoolean(subtree, "selected", 0) == 1) { xsConcatenate(&xs,"sel:1,",6); } if (wgtrGetPropertyValue(subtree,"value",DATA_T_STRING,POD(&ptr)) != 0) { mssError(1,"HTDD","Drop Down widget must have a 'value' property"); return -1; } strtcpy(string,ptr, sizeof(string)); xsConcatQPrintf(&xs,"value:'%STR&JSSTR'}", string); } else { htrRenderWidget(s, subtree, z+1); } } if (flag) { xsConcatenate(&xs, "]);\n", 4); htrAddScriptInit(s,xs.String); xsDeInit(&xs); } return 0; }
// Validate drive, find block size / sector count, and register drive. int scsi_init_drive(struct drive_s *drive, const char *s, int prio) { struct disk_op_s dop; memset(&dop, 0, sizeof(dop)); dop.drive_g = drive; struct cdbres_inquiry data; int ret = cdb_get_inquiry(&dop, &data); if (ret) return ret; char vendor[sizeof(data.vendor)+1], product[sizeof(data.product)+1]; char rev[sizeof(data.rev)+1]; strtcpy(vendor, data.vendor, sizeof(vendor)); nullTrailingSpace(vendor); strtcpy(product, data.product, sizeof(product)); nullTrailingSpace(product); strtcpy(rev, data.rev, sizeof(rev)); nullTrailingSpace(rev); int pdt = data.pdt & 0x1f; int removable = !!(data.removable & 0x80); dprintf(1, "%s vendor='%s' product='%s' rev='%s' type=%d removable=%d\n" , s, vendor, product, rev, pdt, removable); drive->removable = removable; if (pdt == SCSI_TYPE_CDROM) { drive->blksize = CDROM_SECTOR_SIZE; drive->sectors = (u64)-1; char *desc = znprintf(MAXDESCSIZE, "DVD/CD [%s Drive %s %s %s]" , s, vendor, product, rev); boot_add_cd(drive, desc, prio); return 0; } ret = scsi_is_ready(&dop); if (ret) { dprintf(1, "scsi_is_ready returned %d\n", ret); return ret; } struct cdbres_read_capacity capdata; ret = cdb_read_capacity(&dop, &capdata); if (ret) return ret; // READ CAPACITY returns the address of the last block. // We do not bother with READ CAPACITY(16) because BIOS does not support // 64-bit LBA anyway. drive->blksize = be32_to_cpu(capdata.blksize); if (drive->blksize != DISK_SECTOR_SIZE) { dprintf(1, "%s: unsupported block size %d\n", s, drive->blksize); return -1; } drive->sectors = (u64)be32_to_cpu(capdata.sectors) + 1; dprintf(1, "%s blksize=%d sectors=%d\n" , s, drive->blksize, (unsigned)drive->sectors); // We do not recover from USB stalls, so try to be safe and avoid // sending the command if the (obsolete, but still provided by QEMU) // fixed disk geometry page may not be supported. // // We could also send the command only to small disks (e.g. <504MiB) // but some old USB keys only support a very small subset of SCSI which // does not even include the MODE SENSE command! // if (! CONFIG_COREBOOT && memcmp(vendor, "QEMU", 5) == 0) { struct cdbres_mode_sense_geom geomdata; ret = cdb_mode_sense_geom(&dop, &geomdata); if (ret == 0) { u32 cylinders; cylinders = geomdata.cyl[0] << 16; cylinders |= geomdata.cyl[1] << 8; cylinders |= geomdata.cyl[2]; if (cylinders && geomdata.heads && drive->sectors <= 0xFFFFFFFFULL && ((u32)drive->sectors % (geomdata.heads * cylinders) == 0)) { drive->pchs.cylinders = cylinders; drive->pchs.heads = geomdata.heads; drive->pchs.spt = (u32)drive->sectors / (geomdata.heads * cylinders); } } } char *desc = znprintf(MAXDESCSIZE, "%s Drive %s %s %s" , s, vendor, product, rev); boot_add_hd(drive, desc, prio); return 0; }
/* htosrcRender - generate the HTML code for the page. Don't know what this is, but we're keeping it for now - JJP, JDH */ int htosrcRender(pHtSession s, pWgtrNode tree, int z) { int id; char name[40]; char *ptr; int readahead; int scrollahead; int replicasize; char *sql; char *filter; char *baseobj; pWgtrNode sub_tree; // pObjQuery qy; enum htosrc_autoquery_types aq; int receive_updates; int send_updates; int refresh_interval; int count, i; int ind_activity; int use_having; int qy_reveal_only; char key_objname[32]; if(!s->Capabilities.Dom0NS && !s->Capabilities.Dom1HTML) { mssError(1,"HTOSRC","Netscape DOM or W3C DOM1 HTML support required"); return -1; } /** Get an id for this. **/ id = (HTOSRC.idcnt++); /** Get name **/ if (wgtrGetPropertyValue(tree,"name",DATA_T_STRING,POD(&ptr)) != 0) return -1; strtcpy(name,ptr,sizeof(name)); if (wgtrGetPropertyValue(tree,"replicasize",DATA_T_INTEGER,POD(&replicasize)) != 0) replicasize=6; if (wgtrGetPropertyValue(tree,"readahead",DATA_T_INTEGER,POD(&readahead)) != 0) readahead=replicasize/2; if (wgtrGetPropertyValue(tree,"scrollahead",DATA_T_INTEGER,POD(&scrollahead)) != 0) scrollahead=readahead; /** do queries on this osrc indicate end-user activity? **/ ind_activity = htrGetBoolean(tree, "indicates_activity", 1); /** refresh interval (disabled, setting=0, by default) **/ if (wgtrGetPropertyValue(tree, "refresh_interval", DATA_T_INTEGER, POD(&refresh_interval)) != 0) refresh_interval = 0; /** use HAVING clause for query filtering instead of WHERE? **/ use_having = htrGetBoolean(tree, "use_having_clause", 0); /** Delay query until osrc is visible? **/ /*qy_reveal_only = htrGetBoolean(tree, "delay_query_until_reveal", 0);*/ qy_reveal_only = htrGetBoolean(tree, "revealed_only", 0); /** try to catch mistakes that would probably make Netscape REALLY buggy... **/ if(replicasize==1 && readahead==0) readahead=1; if(replicasize==1 && scrollahead==0) scrollahead=1; if(readahead>replicasize) replicasize=readahead; if(scrollahead>replicasize) replicasize=scrollahead; if(scrollahead<1) scrollahead=1; if(replicasize<1 || readahead<1) { mssError(1,"HTOSRC","You must give positive integer for replicasize and readahead"); return -1; } /** Name/abbreviation of key object in SQL query **/ if (wgtrGetPropertyValue(tree,"key_objname",DATA_T_STRING,POD(&ptr)) != 0) ptr = ""; strtcpy(key_objname, ptr, sizeof(key_objname)); /** Query autostart types **/ if (wgtrGetPropertyValue(tree,"autoquery",DATA_T_STRING,POD(&ptr)) == 0) { if (!strcasecmp(ptr,"onLoad")) aq = OnLoad; else if (!strcasecmp(ptr,"onFirstReveal")) aq = OnFirstReveal; else if (!strcasecmp(ptr,"onEachReveal")) aq = OnEachReveal; else if (!strcasecmp(ptr,"never")) aq = Never; else { mssError(1,"HTOSRC","Invalid autostart type '%s' for objectsource '%s'",ptr,name); return -1; } } else { aq = Unset; } /** Get replication updates from server? **/ receive_updates = htrGetBoolean(tree, "receive_updates", 0); /** Send updates to the server? **/ send_updates = htrGetBoolean(tree, "send_updates", 1); if (wgtrGetPropertyValue(tree,"sql",DATA_T_STRING,POD(&ptr)) == 0) { sql = nmSysStrdup(ptr); } else { mssError(1,"HTOSRC","You must give a sql parameter"); return -1; } if (wgtrGetPropertyValue(tree,"baseobj",DATA_T_STRING,POD(&ptr)) == 0) baseobj = nmSysStrdup(ptr); else baseobj = NULL; if (wgtrGetPropertyValue(tree,"filter",DATA_T_STRING,POD(&ptr)) == 0) filter = nmSysStrdup(ptr); else filter = nmSysStrdup(""); /** create our instance variable **/ htrAddWgtrObjLinkage_va(s, tree, "osrc%POSloader",id); htrAddWgtrCtrLinkage(s, tree, "_parentctr"); htrAddScriptGlobal(s, "osrc_syncid", "0", 0); htrAddScriptGlobal(s, "osrc_relationships", "[]", 0); /** Ok, write the style header items. **/ htrAddStylesheetItem_va(s," #osrc%POSloader { overflow:hidden; POSITION:absolute; VISIBILITY:hidden; LEFT:0px; TOP:1px; WIDTH:1px; HEIGHT:1px; Z-INDEX:0; }\n",id); /** Script initialization call. **/ htrAddScriptInit_va(s," osrc_init({loader:wgtrGetNodeRef(ns,\"%STR&SYM\"), readahead:%INT, scrollahead:%INT, replicasize:%INT, sql:\"%STR&JSSTR\", filter:\"%STR&JSSTR\", baseobj:\"%STR&JSSTR\", name:\"%STR&SYM\", autoquery:%INT, requestupdates:%INT, ind_act:%INT, use_having:%INT, qy_reveal_only:%INT, send_updates:%INT, key_objname:\"%STR&JSSTR\", refresh:%INT});\n", name,readahead,scrollahead,replicasize,sql,filter, baseobj?baseobj:"",name,aq,receive_updates, ind_activity, use_having, qy_reveal_only, send_updates, key_objname, refresh_interval); //htrAddScriptCleanup_va(s," %s.layers.osrc%dloader.cleanup();\n", parentname, id); htrAddScriptInclude(s, "/sys/js/htdrv_osrc.js", 0); htrAddScriptInclude(s, "/sys/js/ht_utils_string.js", 0); htrAddScriptInclude(s, "/sys/js/ht_utils_hints.js", 0); /** HTML body element for the frame **/ htrAddBodyItemLayerStart(s,HTR_LAYER_F_DYNAMIC,"osrc%POSloader",id); htrAddBodyItemLayerEnd(s,HTR_LAYER_F_DYNAMIC); htrAddBodyItem(s, "\n"); count = xaCount(&(tree->Children)); for (i=0;i<count;i++) { sub_tree = xaGetItem(&(tree->Children), i); #if 00 if (wgtrGetPropertyValue(sub_tree, "outer_type", DATA_T_STRING, POD(&ptr)) == 0 && !strcmp(ptr, "widget/osrc-rule")) { htosrc_internal_AddRule(s, tree, name, sub_tree); } else { #endif htrRenderWidget(s, sub_tree, z); #if 00 } #endif } nmSysFree(filter); if (baseobj) nmSysFree(baseobj); nmSysFree(sql); return 0; }