/* * filter the permissions we have on the entry into buckets */ void record_access_level(const char *path, struct stat *sb) { if (is_setuid(sb)) record_access(&g_suid, path, sb); else if (is_setgid(sb)) record_access(&g_sgid, path, sb); else if (is_writable(sb)) record_access(&g_writable, path, sb); #ifdef RECORD_LESS_INTERESTING else if (is_readable(sb)) record_access(&g_readable, path, sb); else if (is_executable(sb)) record_access(&g_executable, path, sb); #endif }
void BrowserNode::paintCell(QPainter * p, const QColorGroup & cg, int column, int width, int alignment) { const QColor & bg = p->backgroundColor(); if (is_marked) { p->setBackgroundMode(::Qt::OpaqueMode); p->setBackgroundColor(UmlRedColor); } p->setFont((is_writable()) ? BoldFont : NormalFont); Q3ListViewItem::paintCell(p, cg, column, width, alignment); if (is_marked) { p->setBackgroundMode(::Qt::TransparentMode); p->setBackgroundColor(bg); } }
/** * write - 写入函数 * Param : data 要写入的数据 * len 数据长度 * Return: 默认为已写入的数据长度,-1为写入失败 */ int CtFile::write(const void *data, const size_t len) { if( ! ( is_open() && is_writable() )) return -1; if( data == nullptr || len == 0 ) return -1; int ret; #ifdef WIN32 { /*** microsoft ***/ if( ! WriteFile(m_file_handle,data, len, (LPDWORD)&ret, nullptr) ) ret = -1; } #else { /*** Unix ***/ ret = write(m_file_handle, data, len); } #endif return ret; }
static PyObject * mmap_write_byte_method(mmap_object *self, PyObject *args) { char value; CHECK_VALID(NULL); if (!PyArg_ParseTuple(args, "b:write_byte", &value)) return(NULL); if (!is_writable(self)) return NULL; if (self->pos < self->size) { self->data[self->pos++] = value; Py_RETURN_NONE; } else { PyErr_SetString(PyExc_ValueError, "write byte out of range"); return NULL; } }
static PyObject * mmap_write_method(mmap_object *self, PyObject *args) { Py_ssize_t length; char *data; CHECK_VALID(NULL); if (!PyArg_ParseTuple(args, "y#:write", &data, &length)) return(NULL); if (!is_writable(self)) return NULL; if ((self->pos + length) > self->size) { PyErr_SetString(PyExc_ValueError, "data out of range"); return NULL; } memcpy(self->data+self->pos, data, length); self->pos = self->pos+length; Py_INCREF(Py_None); return Py_None; }
static PyObject * mmap_write_byte_method(mmap_object *self, PyObject *args) { char value; CHECK_VALID(NULL); if (!PyArg_ParseTuple(args, "b:write_byte", &value)) return(NULL); if (!is_writable(self)) return NULL; if (self->pos < self->size) { *(self->data+self->pos) = value; self->pos += 1; Py_INCREF(Py_None); return Py_None; } else { PyErr_SetString(PyExc_ValueError, "write byte out of range"); return NULL; } }
void diag(FILE *output) { char *yn[] = { "No", "Yes", "Unknown" }; fprintf(output,"CVSNT Diagnostic output\n"); fprintf(output,"-----------------------\n"); fprintf(output,"\n"); fprintf(output,"Server version: "CVSNT_PRODUCTVERSION_STRING"\n"); fprintf(output,"OS Version: %s\n",get_os_version()); fprintf(output,"\n"); fprintf(output,"CVS Service installed: %s\n",service_installed("Cvsnt")?"Yes":"No"); fprintf(output,"LockService installed: %s\n",service_installed("CvsLock")?"Yes":"No"); fprintf(output,"\n"); fprintf(output,":pserver: installed: %s\n",protocol_installed("pserver")?"Yes":"No"); fprintf(output,":sserver: installed: %s\n",protocol_installed("sserver")?"Yes":"No"); fprintf(output,":gserver: installed: %s\n",protocol_installed("gserver")?"Yes":"No"); fprintf(output,":server: installed: %s\n",protocol_installed("server")?"Yes":"No"); fprintf(output,":ssh: installed: %s\n",protocol_installed("ssh")?"Yes":"No"); fprintf(output,":sspi: installed: %s\n",protocol_installed("sspi")?"Yes":"No"); fprintf(output,":ext: installed: %s\n",protocol_installed("ext")?"Yes":"No"); fprintf(output,"\n"); fprintf(output,"Installation Path: %s\n",get_reg_string("InstallPath")); fprintf(output,"Repository 0 Path: %s\n",get_reg_string("Repository0")); fprintf(output,"Repository 0 Name: %s\n",get_reg_string("Repository0Name")); fprintf(output,"Repository 1 Path: %s\n",get_reg_string("Repository1")); fprintf(output,"Repository 1 Name: %s\n",get_reg_string("Repository1Name")); fprintf(output,"Repository 2 Path: %s\n",get_reg_string("Repository2")); fprintf(output,"Repository 2 Name: %s\n",get_reg_string("Repository2Name")); fprintf(output,"Repository 3 Path: %s\n",get_reg_string("Repository3")); fprintf(output,"Repository 3 Name: %s\n",get_reg_string("Repository3Name")); fprintf(output,"CVS Temp directory: %s\n",get_reg_string("TempDir")); fprintf(output,"CA Certificate File: %s\n",get_reg_string("CertificateFile")); fprintf(output,"Private Key File: %s\n",get_reg_string("PrivateKeyFile")); fprintf(output,"Local Users Only: %s\n",get_reg_int("DontUseDomain")?"Yes":"No"); fprintf(output,"Default LockServer: %s\n",get_reg_string("LockServer")); fprintf(output,"Disable Reverse DNS: %s\n",get_reg_int("NoReverseDns")?"Yes":"No"); fprintf(output,"Server Tracing: %s\n",get_reg_int("AllowTrace")?"Yes":"No"); fprintf(output,"Case Sensitive: %s\n",get_reg_int("CaseSensitive")?"Yes":"No"); fprintf(output,"Server listen port: %d\n",get_reg_int("PServerPort")); fprintf(output,"Compatibility (Non-cvsnt clients):\n"); fprintf(output,"\tReport old CVS version: %s\n",get_reg_int("Compat0_OldVersion")?"Yes":"No"); fprintf(output,"\tHide extended status: %s\n",get_reg_int("Compat0_HideStatus")?"Yes":"No"); fprintf(output,"\tEmulate co -n bug: %s\n",get_reg_int("Compat0_OldCheckout")?"Yes":"No"); fprintf(output,"\tIgnore client wrappers: %s\n",get_reg_int("Compat0_IgnoreWrappers")?"Yes":"No"); fprintf(output,"Compatibility (CVSNT clients):\n"); fprintf(output,"\tReport old CVS version: %s\n",get_reg_int("Compat1_OldVersion")?"Yes":"No"); fprintf(output,"\tHide extended status: %s\n",get_reg_int("Compat1_HideStatus")?"Yes":"No"); fprintf(output,"\tEmulate co -n bug: %s\n",get_reg_int("Compat1_OldCheckout")?"Yes":"No"); fprintf(output,"\tIgnore client wrappers: %s\n",get_reg_int("Compat1_IgnoreWrappers")?"Yes":"No"); fprintf(output,"Default domain: %s\n",get_reg_string("DefaultDomain")); fprintf(output,"Force run as user: %s\n",get_reg_string("RunAsUser")); fprintf(output,"\n"); fprintf(output,"Temp dir readable by current user: %s\n",yn[is_readable(false,get_reg_string("TempDir"))]); // fprintf(output,"Temp dir readable by LocalSystem: %s\n",yn[is_readable(true,get_reg_string("TempDir"))]); fprintf(output,"Repository0 readable by current user: %s\n",yn[is_readable(false,get_reg_string("Repository0"))]); // fprintf(output,"Repository0 readable by LocalSystem: %s\n",yn[is_readable(true,get_reg_string("Repository0"))]); fprintf(output,"Temp dir writable by current user: %s\n",yn[is_writable(false,get_reg_string("TempDir"))]); // fprintf(output,"Temp dir writable by LocalSystem: %s\n",yn[is_writable(true,get_reg_string("TempDir"))]); fprintf(output,"\n"); fprintf(output,"AV files detected:\n"); print_found_files(output,"_AVP32.EXE\0_AVPCC.EXE\0_AVPM.EXE\0AVP32.EXE\0AVPCC.EXE\0AVPM.EXE\0" "N32SCANW.EXE\0NAVAPSVC.EXE\0NAVAPW32.EXE\0NAVLU32.EXE\0NAVRUNR.EXE\0NAVW32.EXE" "NAVWNT.EXE\0NOD32.EXE\0NPSSVC.EXE\0NRESQ32.EXE\0NSCHED32.EXE\0NSCHEDNT.EXE" "NSPLUGIN.EXE\0SCAN.EXE\0AVGSRV.EXE\0AVGSERV.EXE\0AVGCC32.EXE\0AVGCC.EXE\0" "AVGAMSVR.EXE\0AVGUPSVC.EXE\0NOD32KRN.EXE\0NOD32KUI.EXE\0"); fprintf(output,"\n"); WSADATA wsa = {0}; if(WSAStartup(MAKEWORD(2,0),&wsa)) fprintf(output,"Winsock intialisation failed!\n"); else { fprintf(output,"Installed Winsock protocols:\n\n"); DWORD dwSize=0; LPWSAPROTOCOL_INFO proto; WSAEnumProtocols(NULL,NULL,&dwSize); proto=(LPWSAPROTOCOL_INFO)malloc(dwSize); WSAEnumProtocols(NULL,proto,&dwSize); for(int n=0; n<(int)(dwSize/sizeof(proto[0])); n++) { if(!strncmp(proto[n].szProtocol,"MSAFD NetBIOS",13)) continue; // Ignore netbios layers fprintf(output,"%d: %s\n",proto[n].dwCatalogEntryId,proto[n].szProtocol); } free(proto); } }
int checkpath(int argc, char **argv) { int opt; uid_t uid = geteuid(); gid_t gid = getgid(); mode_t mode = 0; struct passwd *pw = NULL; struct group *gr = NULL; inode_t type = inode_unknown; int retval = EXIT_SUCCESS; bool trunc = false; bool chowner = false; bool writable = false; bool selinux_on = false; while ((opt = getopt_long(argc, argv, getoptstring, longopts, (int *) 0)) != -1) { switch (opt) { case 'D': trunc = true; case 'd': type = inode_dir; break; case 'F': trunc = true; case 'f': type = inode_file; break; case 'p': type = inode_fifo; break; case 'm': if (parse_mode(&mode, optarg) != 0) eerrorx("%s: invalid mode `%s'", applet, optarg); break; case 'o': chowner = true; if (parse_owner(&pw, &gr, optarg) != 0) eerrorx("%s: owner `%s' not found", applet, optarg); break; case 'W': writable = true; break; case_RC_COMMON_GETOPT } } if (optind >= argc) usage(EXIT_FAILURE); if (writable && type != inode_unknown) eerrorx("%s: -W cannot be specified along with -d, -f or -p", applet); if (pw) { uid = pw->pw_uid; gid = pw->pw_gid; } if (gr) gid = gr->gr_gid; if (selinux_util_open() == 1) selinux_on = true; while (optind < argc) { if (writable) exit(!is_writable(argv[optind])); if (do_check(argv[optind], uid, gid, mode, type, trunc, chowner, selinux_on)) retval = EXIT_FAILURE; optind++; } if (selinux_on) selinux_util_close(); return retval; }
static int mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value) { CHECK_VALID(-1); if (!is_writable(self)) return -1; if (PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); Py_ssize_t v; if (i == -1 && PyErr_Occurred()) return -1; if (i < 0) i += self->size; if (i < 0 || i >= self->size) { PyErr_SetString(PyExc_IndexError, "mmap index out of range"); return -1; } if (value == NULL) { PyErr_SetString(PyExc_TypeError, "mmap doesn't support item deletion"); return -1; } if (!PyIndex_Check(value)) { PyErr_SetString(PyExc_TypeError, "mmap item value must be an int"); return -1; } v = PyNumber_AsSsize_t(value, PyExc_TypeError); if (v == -1 && PyErr_Occurred()) return -1; if (v < 0 || v > 255) { PyErr_SetString(PyExc_ValueError, "mmap item value must be " "in range(0, 256)"); return -1; } self->data[i] = (char) v; return 0; } else if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelen; Py_buffer vbuf; if (PySlice_Unpack(item, &start, &stop, &step) < 0) { return -1; } slicelen = PySlice_AdjustIndices(self->size, &start, &stop, step); if (value == NULL) { PyErr_SetString(PyExc_TypeError, "mmap object doesn't support slice deletion"); return -1; } if (PyObject_GetBuffer(value, &vbuf, PyBUF_SIMPLE) < 0) return -1; if (vbuf.len != slicelen) { PyErr_SetString(PyExc_IndexError, "mmap slice assignment is wrong size"); PyBuffer_Release(&vbuf); return -1; } if (slicelen == 0) { } else if (step == 1) { memcpy(self->data + start, vbuf.buf, slicelen); } else { Py_ssize_t cur, i; for (cur = start, i = 0; i < slicelen; cur += step, i++) { self->data[cur] = ((char *)vbuf.buf)[i]; } } PyBuffer_Release(&vbuf); return 0; } else { PyErr_SetString(PyExc_TypeError, "mmap indices must be integer"); return -1; } }
/* open a serial-port device file, without possibly nasty side-effects. * If successful, a newly-open file-descriptor is returned. Otherwise, -1 * is returned and errno is set to reflect the error. * The semantics of open() are used, except that: * * (1) the file is opened without waiting for DCD to be asserted; * * (2) the file is opened with signal-on-serial-break (termios BRKINT) * disabled, and the open is done atomically with respect to SIGINT. * * (3) flags which do not make sense for serial-port devices are ignored * (O_CREAT, O_EXCL, O_TRUNC, O_APPEND). * * (4) Upon successful open, the serial-port's initial termios modes * (before suppression of BRKINT) are recorded at *saved_termios, * so that the caller can restore the extant port settings before * exit()-ing or close()-ing the file. NOTE: closetty() does such * a restore atomically with respect to SIGINT. * * (5) The error ENOTTY is delivered if the specified name does not * refer to a serial-port device. * * (6) If the file name is NULL, empty or "-", a new file-descriptor * referring to the same file as standard-output is generated, * rather than actually open()-ing the file. */ INT opentty(const CHAR *name, INT oflag, struct termios *save) { INT fd; struct termios tm; sigset_t mask, oldmask; assert(name && *name); oflag &= ~(O_CREAT|O_EXCL|O_TRUNC|O_APPEND); /* must block SIGINT to avoid possible interrruption between * open() and supression of termios BRKINT mode... * NOTE: must ensure that we can restore the current signal mask * when finished. */ sigemptyset(&mask); sigemptyset(&oldmask); sigaddset(&mask, SIGINT); sigprocmask(SIG_BLOCK, &mask, &oldmask); if (!strcmp(name, "-")) { fd = dup(STDOUT_FILENO); switch (oflag & O_ACCMODE) { case O_RDONLY: if (!is_readable(fd)) { sigprocmask(SIG_SETMASK, &oldmask, NULL); close(fd); return (-1); } break; case O_WRONLY: if (!is_writable(fd)) { sigprocmask(SIG_SETMASK, &oldmask, NULL); close(fd); return (-1); } break; default: if (!is_readable(fd) || !is_writable(fd)) { sigprocmask(SIG_SETMASK, &oldmask, NULL); close(fd); return (-1); } break; } } else { /* initially open with explicit O_NONBLOCK to avoid waiting for * carrier-detect during open(): */ if ((fd = open(name, oflag|O_NONBLOCK, 0)) < 0) { sigprocmask(SIG_SETMASK, &oldmask, NULL); return (-1); } } /* now set desired file-status flags: */ oflag &= ~O_ACCMODE; if (fcntl(fd, F_SETFL, oflag) < 0) { sigprocmask(SIG_SETMASK, &oldmask, NULL); close(fd); return (-1); } /* record original termios modes, for restore-on-close; and turn off * BRKINT mode on the port; ....notice that this will catch * the ENOTTY error as a handy side effect. */ if ((tcgetattr(fd, save) < 0) || (tcgetattr(fd, &tm) < 0)) { sigprocmask(SIG_SETMASK, &oldmask, NULL); close(fd); return (-1); } tm.c_iflag &= ~BRKINT; if (tcsetattr(fd, TCSAFLUSH, &tm) < 0) { sigprocmask(SIG_SETMASK, &oldmask, NULL); close(fd); return (-1); } tcflush(fd, TCIOFLUSH); /* paranoia! */ /* now is safe to unblock SIGINT: */ sigprocmask(SIG_SETMASK, &oldmask, NULL); /* all done! */ return (fd); }
void BrowserNode::mark_menu(Q3PopupMenu & m, const char * s, int bias) const { if (! is_marked) { m.insertSeparator(); m.setWhatsThis(m.insertItem(TR("Mark"), bias), TR("to mark %1", s)); if (!marked_list.isEmpty()) { bool parents_marked = FALSE; const BrowserNode * bn = this; while (bn != BrowserView::get_project()) { bn = (BrowserNode *) bn->parent(); if (bn->is_marked) { parents_marked = TRUE; break; } } bool moveable = TRUE; #ifndef SIMPLE_DUPLICATION bool rec = FALSE; #endif Q3PtrListIterator<BrowserNode> it(marked_list); for (; (bn = it.current()) != 0; ++it) { if ((bn == BrowserView::get_project()) || !((BrowserNode *) bn->parent())->is_writable()) { moveable = FALSE; #ifndef SIMPLE_DUPLICATION } if (bn->firstChild() != 0) { rec = TRUE; #else break; #endif } } BooL duplicable_into = TRUE; BooL duplicable_after = TRUE; bool into = may_contains_them(marked_list, duplicable_into) && is_writable(); bool after = (this != BrowserView::get_project()) && ((BrowserNode *) parent())->is_writable() && ((BrowserNode *) parent())->may_contains_them(marked_list, duplicable_after); if (!parents_marked) { if (moveable) { if (into) m.setWhatsThis(m.insertItem(TR("Move marked into"), bias + 3), TR("to move the marked items into %1", s)); if (after) m.setWhatsThis(m.insertItem(TR("Move marked after"), bias + 4), TR("to move the marked items after %1", s)); } } if (into && duplicable_into) { m.setWhatsThis(m.insertItem(TR("Duplicate marked into"), bias + 5), TR("to duplicate the marked items into %1", s)); #ifndef SIMPLE_DUPLICATION if (rec && !parents_marked) m.setWhatsThis(m.insertItem(TR("Duplicate recursivelly marked into"), bias + 6), TR("to recurcivelly duplicate the marked items into %1", s)); #endif } if (after && duplicable_after) { m.setWhatsThis(m.insertItem(TR("Duplicate marked after"), bias + 7), TR("to duplicate the marked items after %1", s)); #ifndef SIMPLE_DUPLICATION if (rec && !parents_marked) m.setWhatsThis(m.insertItem(TR("Duplicate marked recursivelly after"), bias + 8), TR("to recurcivelly duplicate the marked items after %1", s)); #endif } } } else { m.insertSeparator(); m.setWhatsThis(m.insertItem(TR("Unmark"), bias + 1), TR("to unmark %1", s)); if (!marked_list.isEmpty()) m.setWhatsThis(m.insertItem(TR("Unmark all"), bias + 2), QString(TR("to unmark all the marked items"))); } }
bool BrowserNode::delete_internal(QString & warning) { if (deletedp()) return TRUE; if (!is_writable() && !root_permission() && !is_from_lib()) { warning += "\n " + TR("%1 is read-only", full_name()); return FALSE; } static Q3PtrList<BrowserNode> targetof; static bool made = FALSE; bool made_here; if (!made) { made = TRUE; made_here = TRUE; referenced_by(targetof, TRUE); } else made_here = FALSE; bool ro = FALSE; if (!root_permission()) { Q3PtrListIterator<BrowserNode> it(targetof); BrowserNode * r; while ((r = it.current()) != 0) { if (!r->is_writable() && !r->is_from_lib()) { ro = TRUE; warning += "\n "; switch (r->get_type()) { case UmlComponent: warning += TR("%1 referenced by the read-only component %2", full_name(), r->full_name()); break; case UmlArtifact: warning += TR("%1 referenced by the read-only artifact %2", full_name(), r->full_name()); break; default: warning += TR("%1 is the target of the read-only relation %2", full_name(), r->full_name()); break; } } ++it; } } if (made_here) { made = FALSE; targetof.clear(); } if (ro) return FALSE; // sub elts Q3ListViewItem * child; bool ok = TRUE; for (child = firstChild(); child != 0; child = child->nextSibling()) ok &= ((BrowserNode *) child)->delete_internal(warning); if (ok) { is_deleted = TRUE; if (is_marked) { marked_list.removeRef(this); is_marked = FALSE; } get_data()->delete_it(); repaint(); package_modified(); } return ok; }
string amiq_rm_field::to_string() { ostringstream convert; convert << name << " Lsb Position: " << lsb_position << " Size: " << size << " W: " << is_writable() << " R: " << is_readable() << " Reset: " << reset_value; return convert.str(); }