~Memory () { if ( _allocationTag == DEALLOCATED ) { cerr << "Attempt to delete an already deleted object " << (void*)this << " of class " << id2name (CID) << "\n"; exit (EXIT_FAILURE); } if ( ! isValid () ) { cerr << "Trying to delete an object of class " << id2name (CID) << ", but accessing an invalid memory piece\n"; exit (EXIT_FAILURE); } // mark the object as de-allocated _allocationTag = DEALLOCATED; if (_next) { _next->_previous = _previous; } if (_previous) { _previous->_next = _next; } if ( _allocated == this ) { _allocated = _next ? _next : _previous; } // free-list will be changed by operator delete }
u32int logfsflattenentry(LogfsIdentityStore *is, uchar *buf, u32int limit, Entry *e) { int unamelen, gnamelen, munamelen, namelen; uint len; uchar *p; int unamebad = 0, gnamebad = 0, munamebad = 0; char *uname, *gname, *muname; id2name(is, e->uid, &uname, &unamebad, &unamelen); id2name(is, e->gid, &gname, &gnamebad, &gnamelen); id2name(is, e->muid, &muname, &munamebad, &munamelen); namelen = strlen(e->name); len = 49 + unamelen + unamebad + gnamelen + gnamebad + munamelen + munamebad + namelen; if(buf == nil) return len; if(len > limit) return 0; p = buf; /* size */ PBIT16(p, len - BIT16SZ); p += BIT16SZ; /* type */ p += BIT16SZ; /* dev */ p += BIT32SZ; /* qid.type */ *p++ = e->qid.type; /* qid.vers */ PBIT32(p, e->qid.vers); p += BIT32SZ; /* qid.path */ PBIT64(p, e->qid.path); p+= 8; /* mode */ PBIT32(p, e->perm); p+= BIT32SZ; /* atime */ PBIT32(p, e->mtime); p+= BIT32SZ; /* mtime */ PBIT32(p, e->mtime); p+= BIT32SZ; /* length */ if(e->qid.type & QTDIR) { PBIT64(p, 0); p += 8; } else { PBIT32(p, e->u.file.length); p += BIT32SZ; PBIT32(p, 0); p += BIT32SZ; } /* name */ PBIT16(p, namelen); p += BIT16SZ; memmove(p, e->name, namelen); p+= namelen; /* uid */ PBIT16(p, unamelen + unamebad); p += BIT16SZ; if(unamebad) *p++ = '('; memmove(p, uname, unamelen + unamebad); p+= unamelen; if(unamebad) *p++ = ')'; /* gid */ PBIT16(p, gnamelen + gnamebad); p += BIT16SZ; if(gnamebad) *p++ = '('; memmove(p, gname, gnamelen); p+= gnamelen; if(gnamebad) *p++ = ')'; /* muid */ PBIT16(p, munamelen + munamebad); p += BIT16SZ; if(munamebad) *p++ = '('; memmove(p, muname, munamelen); p+= munamelen; if(munamebad) *p = ')'; //print("len %ud p - buf %ld\n", len, p - buf); return len; }
/* * this function converts a buffer into a string of resource names. * state (on/off) for resources of interest is selected by the third argument. * accounting type is selected by the fourth argument. * it is caller's responsibility to free the allocated string buffer. */ char * buf2str(ac_res_t *buffer, size_t bufsz, int state, int type) { int i, j, ok, id; char *str, *g; ac_res_t *buf, *cur; if ((buf = malloc(bufsz)) == NULL || (str = malloc(MAXRESLEN)) == NULL) die(gettext("not enough memory\n")); (void) memset(str, 0, MAXRESLEN); (void) memcpy(buf, buffer, bufsz); /* * check if buf has any resource groups in it */ for (i = 0; (g = ac_groups[i].ag_name) != NULL; i++) { if (ac_groups[i].ag_type != type) continue; for (j = 0; (id = ac_groups[i].ag_mem[j]) != AC_NONE; j++) { ok = 1; if (resget(buf, id) != state) { ok = 0; break; } } if (ok) { /* buf contains this resource group */ if (strlen(str) != 0) (void) strcat(str, ","); (void) strcat(str, g); for (j = 0; (id = ac_groups[i].ag_mem[j]) != AC_NONE; j++) resset(buf, id, state == AC_ON ? AC_OFF : AC_ON); ok = 0; } } /* * browse through the rest of the buf for all remaining resources * that are not a part of any groups */ for (cur = buf; cur->ar_id != AC_NONE; cur++) { if (cur->ar_state == state) { if (strlen(str) != 0) (void) strcat(str, ","); if (id2name(cur->ar_id, type) == NULL) die(gettext("unknown %s resource id (%d)\n"), type == AC_PROC ? "process" : "task", cur->ar_id); (void) strcat(str, id2name(cur->ar_id, type)); } } if (strlen(str) == 0) (void) strcpy(str, AC_STR_NONE); free(buf); return (str); }
static void printgroup(int type) { int r, g, id; for (g = 0; ac_groups[g].ag_type != AC_NONE; g++) { if (ac_groups[g].ag_type != type) continue; (void) printf("%-9s", ac_groups[g].ag_name); (void) printf("%s", id2name(ac_groups[g].ag_mem[0], type)); for (r = 1; (id = ac_groups[g].ag_mem[r]) != AC_NONE; r++) (void) printf(",%s", id2name(id, type)); (void) printf("\n"); } }
~LeakChecker () { if (Memory::_allocated) { int leaks = 0; for (Memory* n = Memory::_allocated; n; n = n->_next) { leaks ++; } for (Memory* p = Memory::_allocated->_previous; p; p = p->_previous) { leaks ++; } cout << "Class " << id2name (CID) << "\n" " allocations: " << Memory::_allocs << "\n" " deallocations: " << Memory::_deallocs << "\n"; cout << "Class " << id2name (CID) << " has memory leaks (" << leaks << " pieces)\n"; } }
const char *M680X_group_name(csh handle, unsigned int id) { #ifndef CAPSTONE_DIET return id2name(s_group_names, ARR_SIZE(s_group_names), id); #else return NULL; #endif }
const char *BPF_group_name(csh handle, unsigned int id) { #ifndef CAPSTONE_DIET return id2name(group_name_maps, ARR_SIZE(group_name_maps), id); #else return NULL; #endif }
void Unpup(const char* folder){ u32 i; char folder_2[200]; if(read_only!=1){ DIR *dip; i=0; do{ sprintf(folder_2,"%s_%u",folder,i++); }while((dip = opendir(folder_2)) != NULL); closedir(dip); MKDIR(folder_2, 0777); chdir(folder_2); } const char *file_name; if(read_only!=0) printf("Read Only Mode!\n"); printf("Reading...\n"); u64 HDR = be64(pup); if(HDR!=PSV_HDR) fail("\nERROR! Not a PlayStation Vita Update File (%08x%08x)",HDR>>32,HDR); u32 pkg_version = le32(pup+0x08); u32 img_version = le32(pup+0x10); file_count = le32(pup+0x18); u32 hdr_lenght = le32(pup+0x20); u32 pkg_lenght = le32(pup+0x28); dmsg("HDR 0x%08x%08x\n",HDR>>32,HDR); dmsg("PKG VERSION 0x%08x\n",pkg_version); dmsg("IMG VERSION 0x%08x\n",img_version); printf("N of Files %u\n",file_count); dmsg("HDR Lenght 0x%08x\n",hdr_lenght); dmsg("PKG Lenght 0x%08x\n",pkg_lenght); dmsg("Table Lenght 0x%08x\n",0x80+(0x20*file_count)); u32 entry,offset,size; for(i=0;i<file_count;i+=0x1){ entry = le32(pup+0x80+0x20*i); offset = le32(pup+0x80+0x20*i+0x08); size = le32(pup+0x80+0x20*i+0x10); file_name = id2name(entry, t_names, NULL); if(file_name==NULL){ dmsg("unknown entry id: 0x%08x | Offset: 0x%08x\n",entry,offset); snprintf(unknown_name,256,"unknown_data_0x%x_%02d.data",entry,unknown_type++); file_name = unknown_name; } printf("Found: %30s | size: %10u Bytes\n",file_name,size); if(read_only!=1) memcpy_to_file(file_name, pup + offset, size); } if(read_only!=1){ dmsg("Writing security_1.."); Write("security_1",0x30,0x50); } printf("Done!\n"); }
void dumpAttribute(CK_ATTRIBUTE_PTR attr) { char attribute[30], scr[200]; unsigned long atype; strcpy(attribute, id2name(p11CKAName, attr->type, &atype)); // printf("\n %s", attribute); switch(attr->type) { case CKA_KEY_TYPE: debug("\n %s = %s\n", attribute, id2name(p11CKKName, *(CK_KEY_TYPE *)attr->pValue, NULL)); break; default: switch(atype) { case CKT_BBOOL: if (attr->pValue) { debug("\n %s = %s [%d]\n", attribute, *(CK_BBOOL *)attr->pValue ? "TRUE" : "FALSE", *(CK_BBOOL *)attr->pValue); } else { debug("\n %s\n", attribute); } break; case CKT_DATE: // pdate = (CK_DATE *)attr->pValue; // if (pdate != NULL) { // sprintf(res, " %s = %4s-%2s-%2s", attribute, pdate->year, pdate->month, pdate->day); // } debug("\n %s\n", attribute); break; case CKT_LONG: debug("\n %s = %d [0x%X]\n", attribute, *(CK_LONG *)attr->pValue, *(CK_LONG *)attr->pValue); break; case CKT_ULONG: debug("\n %s = %u [0x%X]\n", attribute, *(CK_ULONG *)attr->pValue, *(CK_ULONG *)attr->pValue); break; case CKT_BIN: default: bin2str(scr, sizeof(scr), attr->pValue, attr->ulValueLen); debug("\n %s = %s\n", attribute, scr); break; } } }
/* this is for the master to receive the acknowledgement. */ void wait_for_ok(int code) { int i, count, resp; time_t tloc; time_t rtime0, rtime1; rtime0 = time(&tloc); /* reference time */ count = 0; while (!all_machine_ok()) { resp = read_handle_complaint(code); if (resp==1) { /* if there is a complaint handled */ rtime0 = time(&tloc); /* reset the reference time */ continue; } if (resp==0) { /* irrelevant complaint received */ continue; } /* no complaints handled within the time period set by set_delay() */ rtime1 = time(&tloc); /* time since last complaints */ if ((rtime1-rtime0) >= ACK_WAIT_PERIOD) { ++count; if (count < my_ACK_WAIT_TIMES) { if (verbose>=1 && (count % 10 == 0)) fprintf(stderr, " %d: resend cmd(%s) to machines:[ ", count, cmd_name[code]); for(i=0; i<nMachines; ++i) { if (machine_status[i] == NOT_READY && bad_machines[i] == GOOD_MACHINE) { if (verbose>=1 && (count % 10 == 0)) fprintf(stderr, "%d ", i); send_cmd(code, (int) i); usleep(FAST); } } if (verbose>=1 && (count % 10 == 0)) fprintf(stderr, "]\n"); rtime0 = rtime1; } else { /* allowable period of time has passed */ fprintf(stderr, " Drop these bad machines:[ "); for(i=0; i<nMachines; ++i) { if (machine_status[i] == NOT_READY && bad_machines[i] == GOOD_MACHINE) { /* fprintf(stderr, "%d ", i); */ fprintf(stderr, "%s ", id2name(i)); bad_machines[i]= BAD_MACHINE; /* The pages sent by the master will be ignored by the bad machine, because the current_file nubmer does not match. */ } } fprintf(stderr, "]\n"); break; } } } }
int choose_print_machines(char *stArray, char selection, char * msg_prefix) { int i, count = 0; for(i=0; i<nMachines; ++i) { char line[PATH_MAX]; if (stArray[i] == selection) { ++count; strcpy(line, id2name(i)); if (count == 1) { fprintf(stderr, msg_prefix); } if (strlen(line)==0) fprintf(stderr, "%d ", i); else fprintf(stderr, "%s ", line); } } if (count > 0) fprintf(stderr, "]\n"); return count; }
const char *BPF_insn_name(csh handle, unsigned int id) { #ifndef CAPSTONE_DIET /* We have some special cases because 'ld' in cBPF is equivalent to 'ldw' * in eBPF, and we don't want to see 'ldw' appears in cBPF mode. */ if (!EBPF_MODE(handle)) { switch (id) { case BPF_INS_LD: return "ld"; case BPF_INS_LDX: return "ldx"; case BPF_INS_ST: return "st"; case BPF_INS_STX: return "stx"; } } return id2name(insn_name_maps, ARR_SIZE(insn_name_maps), id); #else return NULL; #endif }
int key_get(enum sce_key type, const char *suffix, struct key *k) { const char *name; char base[256]; char path[256]; u8 tmp[4]; if (key_build_path(base) < 0) return -1; name = id2name(type, t_key2file, NULL); if (name == NULL) return -1; snprintf(path, sizeof path, "%s/%s-key-%s", base, name, suffix); if (key_read(path, 32, k->key) < 0) return -1; snprintf(path, sizeof path, "%s/%s-iv-%s", base, name, suffix); if (key_read(path, 16, k->iv) < 0) return -1; k->pub_avail = k->priv_avail = 1; snprintf(path, sizeof path, "%s/%s-ctype-%s", base, name, suffix); if (key_read(path, 4, tmp) < 0) { k->pub_avail = k->priv_avail = -1; return 0; } k->ctype = be32(tmp); snprintf(path, sizeof path, "%s/%s-pub-%s", base, name, suffix); if (key_read(path, 40, k->pub) < 0) k->pub_avail = -1; snprintf(path, sizeof path, "%s/%s-priv-%s", base, name, suffix); if (key_read(path, 21, k->priv) < 0) k->priv_avail = -1; return 0; }
int pr_missing_pages() { int i, N, exit_code=0; off_t delta; unsigned int dp; for(i=0; i<nMachines; ++i) { char name[PATH_MAX]; N = get_total_missing_pages(i); strcpy(name, id2name(i)); if (strlen(name)==0) sprintf(name, "machine(%3d)", i); fprintf(stderr, "%s: #_missing_page_request = %6.2f%% = %d\n", name, (double)N/((double)total_pages)*100.0, N); } if (skip_count>0) { fprintf(stderr, "\nWarning: There are %d files which are not delivered.\n", skip_count); exit_code = -1; } fprintf(stderr, "\nTotal number of files = %12d Pages w/o ack = %12u (%6.2f%%)\n", total_entries(), pages_wo_ack(), (double)pages_wo_ack()/(double)real_total_pages*100.0); dp = real_total_pages - total_pages; fprintf(stderr, "Total number of pages = %12d Pages re-sent = %12u (%6.2f%%)\n", total_pages, dp, (double)dp/(double)total_pages*100.0); delta = (off_t)(real_total_bytes - total_bytes); #ifdef _LARGEFILE_SOURCE fprintf(stderr, "Total number of bytes = %12llu Bytes re-sent = %12llu (%6.2f%%)\n", total_bytes, delta, (double)delta/(double)total_bytes*100.0); #else fprintf(stderr, "Total number of bytes = %12d Bytes re-sent = %12u (%6.2f%%)\n", total_bytes, delta, (double)delta/(double)total_bytes*100.0); #endif return (exit_code); }
/* * Collect the requested quota information. */ struct dquot *getprivs(qid_t id, struct quota_handle **handles, int quiet) { struct dquot *q, *qtail = NULL, *qhead = NULL; int i; char name[MAXNAMELEN]; #if defined(BSD_BEHAVIOUR) int j, ngroups; uid_t euid; gid_t gidset[NGROUPS], *gidsetp; #endif for (i = 0; handles[i]; i++) { #if defined(BSD_BEHAVIOUR) switch (handles[i]->qh_type) { case USRQUOTA: euid = geteuid(); if (euid != id && euid != 0) { uid2user(id, name); errstr(_("%s (uid %d): Permission denied\n"), name, id); return (struct dquot *)NULL; } break; case GRPQUOTA: if (geteuid() == 0) break; ngroups = sysconf(_SC_NGROUPS_MAX); if (ngroups > NGROUPS) { gidsetp = malloc(ngroups * sizeof(gid_t)); if (!gidsetp) { gid2group(id, name); errstr(_("%s (gid %d): gid set allocation (%d): %s\n"), name, id, ngroups, strerror(errno)); return (struct dquot *)NULL; } } else gidsetp = &gidset[0]; ngroups = getgroups(ngroups, gidsetp); if (ngroups < 0) { if (gidsetp != gidset) free(gidsetp); gid2group(id, name); errstr(_("%s (gid %d): error while trying getgroups(): %s\n"), name, id, strerror(errno)); return (struct dquot *)NULL; } for (j = 0; j < ngroups; j++) if (id == gidsetp[j]) break; if (gidsetp != gidset) free(gidsetp); if (j >= ngroups) { gid2group(id, name); errstr(_("%s (gid %d): Permission denied\n"), name, id); return (struct dquot *)NULL; } break; default: break; } #endif if (!(q = handles[i]->qh_ops->read_dquot(handles[i], id))) { /* If rpc.rquotad is not running filesystem might be just without quotas... */ if (errno != ENOENT && (errno != ECONNREFUSED || !quiet)) { int olderrno = errno; id2name(id, handles[i]->qh_type, name); errstr(_("error while getting quota from %s for %s (id %u): %s\n"), handles[i]->qh_quotadev, name, id, strerror(olderrno)); } continue; } if (qhead == NULL) qhead = q; else qtail->dq_next = q; qtail = q; q->dq_next = NULL; /* This should be already set, but just for sure... */ } return qhead; }
int key_get(enum sce_key type, const char *suffix, struct key *k) { const char *name = ""; const char *rev = ""; char base[256]; char path[256]; u8 tmp[4]; if ( strncmp( suffix, "retail", strlen( suffix ) ) == 0 ) { rev = "retail"; } else if ( atoi( suffix ) <= 92 ) { suffix = "092"; rev = "0x00"; } else if ( atoi( suffix ) <= 331 ) { suffix = "315"; rev = "0x01"; } else if ( atoi( suffix ) <= 342 ) { suffix = "341"; rev = "0x04"; } else if ( atoi( suffix ) <= 350 ) { suffix = "350"; rev = "0x07"; } else if ( atoi( suffix ) <= 355 ) { suffix = "355"; rev = "0x0a"; } else if ( atoi( suffix ) <= 356 ) { suffix = "356"; rev = "0x0d"; } printf(" file suffix: %s (rev %s)\n", suffix, rev ); if (key_build_path(base) < 0) return -1; name = id2name(type, t_key2file, NULL); if (name == NULL) return -1; snprintf(path, sizeof path, "%s/%s-key-%s", base, name, suffix); if (key_read(path, 32, k->key) < 0) { printf(" key file: %s (ERROR)\n", path); return -1; } snprintf(path, sizeof path, "%s/%s-iv-%s", base, name, suffix); if (key_read(path, 16, k->iv) < 0) { printf(" iv file: %s (ERROR)\n", path); return -1; } k->pub_avail = k->priv_avail = 1; snprintf(path, sizeof path, "%s/%s-ctype-%s", base, name, suffix); if (key_read(path, 4, tmp) < 0) { k->pub_avail = k->priv_avail = -1; printf(" ctype file: %s (ERROR)\n", path); return 0; } k->ctype = be32(tmp); snprintf(path, sizeof path, "%s/%s-pub-%s", base, name, suffix); if (key_read(path, 40, k->pub) < 0) { printf(" pub file: %s (ERROR)\n", path); k->pub_avail = -1; } snprintf(path, sizeof path, "%s/%s-priv-%s", base, name, suffix); if (key_read(path, 21, k->priv) < 0) { printf(" priv file: %s (ERROR)\n", path); k->priv_avail = -1; } return 0; }
struct keylist *keys_get(enum sce_key type) { const char *name = NULL; char base[256]; char path[256]; void *tmp = NULL; char *id; DIR *dp; struct dirent *dent; struct keylist *klist; u8 bfr[4]; klist = malloc(sizeof *klist); if (klist == NULL) goto fail; memset(klist, 0, sizeof *klist); name = id2name(type, t_key2file, NULL); if (name == NULL) goto fail; if (key_build_path(base) < 0) goto fail; dp = opendir(base); if (dp == NULL) goto fail; while ((dent = readdir(dp)) != NULL) { if (strncmp(dent->d_name, name, strlen(name)) == 0 && strstr(dent->d_name, "key") != NULL) { tmp = realloc(klist->keys, (klist->n + 1) * sizeof(struct key)); if (tmp == NULL) goto fail; id = strrchr(dent->d_name, '-'); if (id != NULL) id++; klist->keys = tmp; memset(&klist->keys[klist->n], 0, sizeof(struct key)); snprintf(path, sizeof path, "%s/%s-key-%s", base, name, id); key_read(path, 32, klist->keys[klist->n].key); snprintf(path, sizeof path, "%s/%s-iv-%s", base, name, id); key_read(path, 16, klist->keys[klist->n].iv); klist->keys[klist->n].pub_avail = -1; klist->keys[klist->n].priv_avail = -1; snprintf(path, sizeof path, "%s/%s-pub-%s", base, name, id); if (key_read(path, 40, klist->keys[klist->n].pub) == 0) { snprintf(path, sizeof path, "%s/%s-ctype-%s", base, name, id); key_read(path, 4, bfr); klist->keys[klist->n].pub_avail = 1; klist->keys[klist->n].ctype = be32(bfr); } snprintf(path, sizeof path, "%s/%s-priv-%s", base, name, id); if (key_read(path, 21, klist->keys[klist->n].priv) == 0) klist->keys[klist->n].priv_avail = 1; klist->n++; } } return klist; fail: if (klist != NULL) { if (klist->keys != NULL) free(klist->keys); free(klist); } klist = NULL; return NULL; }
int read_handle_complaint(int cmd) { /* cmd = cmd_code -- each cmd expects different 'response' (complaints) return 1 for complaint handled return 0 for irrelevant complaint return -1 for time-out */ int mid_v, code_v, file_v, npage_v, bytes_read; if (readable(complaint_fd)) { /* There is a complaint */ bytes_read = recvfrom(complaint_fd, flow_buff, FLOW_BUFFSIZE, 0, NULL, NULL); /* 20060323 deal with big- vs little-endian issue convert incoming integers into host representation */ mid_v = ntohl(*mid_ptr); if ((bytes_read < FLOW_HEAD_SIZE) || (mid_v < 0 ) || (mid_v >= (unsigned int) nMachines) || /* boundary check for mid_v for safety */ (bad_machines[mid_v] == BAD_MACHINE)) { /* ignore complaint from a bad machine*/ return 0; } code_v = ntohl(*code_ptr); file_v = ntohl(*file_ptr); npage_v = ntohl(*npage_ptr); /* check if the complaint is for the current file */ if (code_v != MONITOR_OK && file_v != current_entry()) return 0; /* out of seq will be ignored */ if (code_v != MISSING_PAGE && code_v != MISSING_TOTAL) { /********* MISSING_TOTAL ? *************/ if (npage_v <= last_seq[mid_v]) return 0; else last_seq[mid_v] = npage_v; } switch (code_v) { case PAGE_RECV: /******** check if machineID is the one we have set. */ /*if (verbose>=2) fprintf(stderr, "mid_ptr-> %d, monitorid = %d\n", mid_v, monitorID);*/ if (cmd == SENDING_DATA && mid_v == monitorID) return 1; else return 0; case MONITOR_OK: /********* check if machineID is the one we have set. */ if (verbose>=2) fprintf(stderr, "mid_ptr-> %d, monitorid = %d\n", mid_v, monitorID); if (cmd == SELECT_MONITOR_CMD && mid_v == monitorID) return 1; else return 0; case OPEN_OK : if (cmd == OPEN_FILE_CMD) { machine_status[mid_v] = MACHINE_OK; return 1; } else { return 0; } case CLOSE_OK : if (cmd == CLOSE_FILE_CMD || cmd == CLOSE_ABORT_CMD) { machine_status[mid_v] = MACHINE_OK; return 1; } else { return 0; } case EOF_OK : if (cmd == EOF_CMD && file_received[mid_v]==NOT_RECV) { machine_status[mid_v] = MACHINE_OK; file_received[mid_v] = FILE_RECV; return 1; } else { return 0; } case MISSING_PAGE : if (cmd != EOF_CMD || file_received[mid_v]==FILE_RECV) return 0; if (npage_v > nPages) return 0; { int i, *pi, page_v; pi = pArray_ptr; for (i = 0; i<npage_v; ++i) { page_v = ntohl(pi[i]); if (page_v<1 || page_v > nPages) continue; /*** make sure page_v starts with 1*/ missing_page_flag[page_v-1] = MISSING; } } missing_pages[mid_v] += npage_v; set_has_missing(); return 1; case MISSING_TOTAL: if (cmd != EOF_CMD || file_received[mid_v]==FILE_RECV || machine_status[mid_v] == MACHINE_OK) return 0; /* Consider to add: if npage_v >missing_pages[mid_v], ask to resend [ likely no big gain ] */ total_missing_page[mid_v] += npage_v; set_has_missing(); /* store the info about missing info */ machine_status[mid_v] = MACHINE_OK; /* machine_status serves as ack only */ return 1; case SIT_OUT : if (cmd != EOF_CMD || file_received[mid_v]==FILE_RECV) return 0; fprintf(stderr, "*** %s sits-out-receiving %s\n", id2name(mid_v), getFilename()); machine_status[mid_v] = MACHINE_OK; if (!has_sick) ++skip_count; set_has_sick(); return 1; default : if (verbose>=2) fprintf(stderr, "Unknown complaint: code = %d\n", code_v); return 0; } /* end of switch */ } /* end of if(readable) */ /* time out of readable() */ return -1; }
void main(int argc, char **argv) { int id, arc; char *arv[4]; char *l, *name; chatty = 1; ARGBEGIN{ case '9': case 'u': style = ARGC(); break; case 'D': ++debug; break; }ARGEND if(argc <= 0){ ids = readunixids("/fd/0", style); if(ids) idprint(1, ids); exits(ids ? 0 : "readunixids"); } mapinit(argv[0], 0); in = Bopen("/fd/0", OREAD); while(l = Brdline(in, '\n')){ /* assign = */ l[Blinelen(in)-1] = 0; arc = strparse(l, nelem(arv), arv); if(arc <= 0) continue; switch(arv[0][0]){ case 'r': if(arc < 2) continue; mapinit(arv[1], arv[2]); break; case 'i': if(arc < 2) continue; id = strtol(arv[1], 0, 10); name = id2name(pids, id); print("%d -> %s\n", id, name); break; case 'n': if(arc < 2) continue; name = arv[1]; id = name2id(pids, name); print("%s -> %d\n", name, id); break; case 'p': print("server=%s, client=%s\n", mp->server, mp->client); break; case 'P': idprint(1, *pids); break; case 'u': pids = &mp->u.ids; print("users...\n"); break; case 'g': pids = &mp->g.ids; print("groups...\n"); break; } } exits(0); }
struct keylist *keys_get(enum sce_key type) { const char *name = NULL; char base[256]; char path[256]; void *tmp = NULL; char *id; DIR *dp; struct dirent *dent; struct keylist *klist; u8 bfr[4]; klist = malloc(sizeof *klist); if (klist == NULL) goto fail; memset(klist, 0, sizeof *klist); name = id2name(type, t_key2file, NULL); if (name == NULL) goto fail; if (key_build_path(base) < 0) goto fail; dp = opendir(base); if (dp == NULL) goto fail; while ((dent = readdir(dp)) != NULL) { if (strncmp(dent->d_name, name, strlen(name)) == 0 && strstr(dent->d_name, "key") != NULL) { tmp = realloc(klist->keys, (klist->n + 1) * sizeof(struct key)); if (tmp == NULL) goto fail; id = strrchr(dent->d_name, '-'); if (id != NULL) id++; klist->keys = tmp; memset(&klist->keys[klist->n], 0, sizeof(struct key)); snprintf(path, sizeof path, "%s/%s-key-%s", base, name, id); if (key_read(path, 32, klist->keys[klist->n].key) != 0) { printf(" key file: %s (ERROR)\n", path); } snprintf(path, sizeof path, "%s/%s-iv-%s", base, name, id); if (key_read(path, 16, klist->keys[klist->n].iv) != 0) { printf(" iv file: %s (ERROR)\n", path); } klist->keys[klist->n].pub_avail = -1; klist->keys[klist->n].priv_avail = -1; snprintf(path, sizeof path, "%s/%s-pub-%s", base, name, id); if (key_read(path, 40, klist->keys[klist->n].pub) == 0) { snprintf(path, sizeof path, "%s/%s-ctype-%s", base, name, id); key_read(path, 4, bfr); klist->keys[klist->n].pub_avail = 1; klist->keys[klist->n].ctype = be32(bfr); } else { printf(" pub file: %s (ERROR)\n", path); } snprintf(path, sizeof path, "%s/%s-priv-%s", base, name, id); if (key_read(path, 21, klist->keys[klist->n].priv) == 0) { klist->keys[klist->n].priv_avail = 1; } else { printf(" priv file: %s (ERROR)\n", path); } klist->n++; } } if (type == KEY_NPDRM) { klist->idps = calloc(sizeof(struct key), 1); if (klist->idps == NULL) goto fail; snprintf(path, sizeof path, "%s/idps", base); if (key_read(path, 16, klist->idps->key) != 0) { printf(" key file: %s (ERROR)\n", path); } klist->klic = calloc(sizeof(struct key), 1); if (klist->klic == NULL) goto fail; snprintf(path, sizeof path, "%s/klic-key", base); if (key_read(path, 16, klist->klic->key) != 0) { printf(" key file: %s (ERROR)\n", path); } klist->rif = calloc(sizeof(struct key), 1); if (klist->rif == NULL) goto fail; snprintf(path, sizeof path, "%s/rif-key", base); if (key_read(path, 16, klist->rif->key) != 0) { printf(" key file: %s (ERROR)\n", path); } klist->npdrm_const = calloc(sizeof(struct key), 1); if (klist->npdrm_const == NULL) goto fail; snprintf(path, sizeof path, "%s/npdrm-const", base); if (key_read(path, 16, klist->npdrm_const->key) != 0) { printf(" key file: %s (ERROR)\n", path); } klist->free_klicensee = calloc(sizeof(struct key), 1); if (klist->free_klicensee == NULL) goto fail; snprintf(path, sizeof path, "%s/free_klicensee-key", base); if (key_read(path, 16, klist->free_klicensee->key) != 0) { printf(" key file: %s (ERROR)\n", path); } } return klist; fail: if (klist != NULL) { if (klist->keys != NULL) free(klist->keys); free(klist); } klist = NULL; return NULL; }
static int setup_ldap(struct configparams *config) { int ret; struct berval cred = { .bv_val = config->ldap_bindpw, .bv_len = strlen(config->ldap_bindpw) }; ret = ldap_initialize(&ldapconn, config->ldap_uri); if (ret != LDAP_SUCCESS) { errstr(_("ldap_initialize() failed: %s\n"), ldap_err2string(ret)); return -1; } ret = ldap_sasl_bind_s(ldapconn, config->ldap_binddn, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL); if(ret < 0) { errstr(_("ldap_sasl_bind_s() failed: %s\n"), ldap_err2string(ret)); return -1; } return 0; } #endif static struct offenderlist *add_offender(int type, int id, char *name) { struct offenderlist *offender; char namebuf[MAXNAMELEN]; if (!name) { if (id2name(id, type, namebuf)) { errstr(_("Cannot get name for uid/gid %u.\n"), id); return NULL; } name = namebuf; } offender = (struct offenderlist *)smalloc(sizeof(struct offenderlist)); offender->offender_type = type; offender->offender_id = id; offender->offender_name = sstrdup(name); offender->usage = (struct usage *)NULL; offender->next = offenders; offenders = offender; return offender; } static void add_offence(struct dquot *dquot, char *name) { struct offenderlist *lptr; struct usage *usage; for (lptr = offenders; lptr; lptr = lptr->next) if (dquot->dq_h->qh_type == lptr->offender_type && lptr->offender_id == dquot->dq_id) break; if (!lptr) if (!(lptr = add_offender(dquot->dq_h->qh_type, dquot->dq_id, name))) return; usage = (struct usage *)smalloc(sizeof(struct usage)); memcpy(&usage->dq_dqb, &dquot->dq_dqb, sizeof(struct util_dqblk)); usage->devicename = sstrdup(dquot->dq_h->qh_quotadev); /* * Stuff it in front */ usage->next = lptr->usage; lptr->usage = usage; } static int deliverable(struct dquot *dquot) { time_t now; struct dquot *mdquot; if (!maildev[0]) return 1; time(&now); if (!strcasecmp(maildev, "any") && ((dquot->dq_dqb.dqb_bhardlimit && toqb(dquot->dq_dqb.dqb_curspace) >= dquot->dq_dqb.dqb_bhardlimit) || ((dquot->dq_dqb.dqb_bsoftlimit && toqb(dquot->dq_dqb.dqb_curspace) >= dquot->dq_dqb.dqb_bsoftlimit) && (dquot->dq_dqb.dqb_btime && dquot->dq_dqb.dqb_btime <= now)))) return 0; if (!maildev_handle) return 1; mdquot = maildev_handle->qh_ops->read_dquot(maildev_handle, dquot->dq_id); if (mdquot && ((mdquot->dq_dqb.dqb_bhardlimit && toqb(mdquot->dq_dqb.dqb_curspace) >= mdquot->dq_dqb.dqb_bhardlimit) || ((mdquot->dq_dqb.dqb_bsoftlimit && toqb(mdquot->dq_dqb.dqb_curspace) >= mdquot->dq_dqb.dqb_bsoftlimit) && (mdquot->dq_dqb.dqb_btime && mdquot->dq_dqb.dqb_btime <= now)))) { free(mdquot); return 0; } free(mdquot); return 1; }
bool CDlgUIList::createDialogCodeFromXML(const char* szFilename,const char* szDialogName) { TiXmlDocument myDocument( strFilename ); myDocument.LoadFile(TIXML_ENCODING_UTF8); if ( myDocument.Error() ) { return false; } std::list<std::wstring> listString; //获得根元素,即root。 TiXmlElement *pRootElement = myDocument.RootElement(); //获得第一个dialog节点。 TiXmlElement *pDialogElement = pRootElement->FirstChildElement("dialog"); while ( pDialogElement ) { if ( pDialogElement->Attribute("id") ) { WCHAR strText[256]={0}; MultiByteToWideChar(CP_UTF8,0,pDialogElement->Attribute("id"),-1,strText,256); if (strDialogName==ws2s(strText)) { { setlocale(LC_ALL,"Chinese-simplified"); std::ofstream ofs("dialog_code.h"); assert(ofs); ofs<<"class CDlg"<<id2name(strDialogName)<<": public CUIDialog"<<std::endl; ofs<<"{"<<std::endl; ofs<<"public:"<<std::endl; ofs<<" virtual void OnControlRegister();"<<std::endl; ofs<<"private:"<<std::endl; ofs<<" // Controls' event."<<std::endl; TiXmlElement *pControlElement = pDialogElement->FirstChildElement("element"); while (pControlElement) { if (pControlElement->Attribute("id")) { std::string strID = pControlElement->Attribute("id"); ofs<<" void On"<<id2name(strID)<<"();"<<std::endl; } pControlElement = pControlElement->NextSiblingElement("element"); } ofs<<" // Controls' variable."<<std::endl; pControlElement = pDialogElement->FirstChildElement("element"); while (pControlElement) { std::string strType = pControlElement->Attribute("type"); if (pControlElement->Attribute("id")) { std::string strID = pControlElement->Attribute("id"); ofs<<" "<<type2ControlClassName(strType)<<" m_"<<id2name(strID)<<";"<<std::endl; } pControlElement = pControlElement->NextSiblingElement("element"); } ofs<<"}"; ofs.close(); } ////////////////////////////////////////////////////////////////////////// { setlocale(LC_ALL,"Chinese-simplified"); std::ofstream ofs("dialog_code.cpp"); assert(ofs); ofs<<"#include \"Dlg"<<id2name(strDialogName)<<".h\""<<std::endl; ofs<<std::endl; ofs<<"void CDlg"<<id2name(strDialogName)<<"::OnControlRegister()"<<std::endl; ofs<<"{"<<std::endl; TiXmlElement *pControlElement = pDialogElement->FirstChildElement("element"); while (pControlElement) { if (pControlElement->Attribute("id")) { std::string strID = pControlElement->Attribute("id"); ofs<<" RegisterControl(\""<<strID<<"\", m_"<<id2name(strID)<<");"<<std::endl; } pControlElement = pControlElement->NextSiblingElement("element"); } ofs<<std::endl; pControlElement = pDialogElement->FirstChildElement("element"); while (pControlElement) { if (pControlElement->Attribute("id")) { std::string strID = pControlElement->Attribute("id"); ofs<<" RegisterControlEvent(\""<<strID<<"\", (PEVENT)&CDlg"<<id2name(strDialogName)<<"::On"<<id2name(strID)<<");"<<std::endl; } pControlElement = pControlElement->NextSiblingElement("element"); } ofs<<"}"; pControlElement = pDialogElement->FirstChildElement("element"); while (pControlElement) { if (pControlElement->Attribute("id")) { std::string strID = pControlElement->Attribute("id"); ofs<<std::endl<<std::endl; ofs<<"void CDlg"<<id2name(strDialogName)<<"::On"<<id2name(strID)<<"()"<<std::endl; ofs<<"{"<<std::endl; ofs<<" // Do it."<<std::endl; ofs<<"}"; } pControlElement = pControlElement->NextSiblingElement("element"); } ofs.close(); } return true; break; } } // 查找下一个dialog pDialogElement = pDialogElement->NextSiblingElement("dialog"); } return true; }
Xfid * rpc2xfid(Rpccall *cmd, Dir *dp) { char *argptr = cmd->args; Xfile *xp; Xfid *xf; Session *s; char *service; Authunix au; Qid qid; char client[256], *user; Unixidmap *m; int i; uvlong x1, x2; chat("rpc2xfid %.8lux %.8lux %p %p\n", *((ulong*)argptr), *((ulong*)argptr+1), buf, argptr); if(argptr[0] == 0 && argptr[1] == 0){ /* root */ chat("root..."); xp = xfroot(&argptr[2], 0); s = xp ? xp->s : 0; }else{ ulong ul; chat("noroot %.8lux...", *((ulong*)argptr)); if((ul=GLONG()) != starttime){ chat("bad tag %lux %lux...", ul, starttime); return 0; } s = (Session *)GLONG(); x1 = GLONG(); x2 = GLONG(); qid.path = x1 | (x2<<32); qid.vers = 0; qid.type = GBYTE(); xp = xfile(&qid, s, 0); } if(xp == 0){ chat("no xfile..."); return 0; } if(auth2unix(&cmd->cred, &au) != 0){ chat("auth flavor=%ld, count=%ld\n", cmd->cred.flavor, cmd->cred.count); for(i=0; i<cmd->cred.count; i++) chat(" %.2ux", ((uchar *)cmd->cred.data)[i]); chat("..."); return 0; }else{ /* chat("auth: %d %.*s u=%d g=%d", * au.stamp, utfnlen(au.mach.s, au.mach.n), au.mach.s, au.uid, au.gid); * for(i=0; i<au.gidlen; i++) * chat(", %d", au.gids[i]); * chat("..."); */ char *p = memchr(au.mach.s, '.', au.mach.n); chat("%ld@%.*s...", au.uid, utfnlen(au.mach.s, (p ? p-au.mach.s : au.mach.n)), au.mach.s); } if(au.mach.n >= sizeof client){ chat("client name too long..."); return 0; } memcpy(client, au.mach.s, au.mach.n); client[au.mach.n] = 0; service = xp->parent->s->service; cmd->up = m = pair2idmap(service, cmd->host); if(m == 0){ chat("no map for pair (%s,%s)...", service, client); /*chat("getdom %d.%d.%d.%d", cmd->host&0xFF, (cmd->host>>8)&0xFF, (cmd->host>>16)&0xFF, (cmd->host>>24)&0xFF);/**/ /*if(getdom(cmd->host, client, sizeof(client))<0) return 0;/**/ return 0; } /*chat("map=(%s,%s)...", m->server, m->client);/**/ cmd->user = user = id2name(&m->u.ids, au.uid); if(user == 0){ chat("no user for id %ld...", au.uid); return 0; } chat("user=%s...", user);/**/ xf = 0; if(s == xp->parent->s){ if(!s->noauth) xf = setuser(xp, user); if(xf == 0) xf = setuser(xp, "none"); if(xf == 0) chat("can't set user none..."); }else xf = xp->users; if(xf) chat("uid=%s...", xf->uid); if(xf && dp && xfstat(xf, dp) < 0){ chat("can't stat %s...", xp->name); return 0; } return xf; }