Exemple #1
0
int runTests() {
  int warning = 0;

  // Test pre-1: check if the user is allowed to dial-out
  if(access("/etc/kppp.allow", R_OK) == 0 && getuid() != 0) {
    bool access = FALSE;
    FILE *f;
    if((f = fopen("/etc/kppp.allow", "r")) != NULL) {
      char buf[2048]; // safe
      while(f != NULL && !feof(f)) {
	if(fgets(buf, sizeof(buf), f) != NULL) {
	  QString s(buf);

	  s = s.stripWhiteSpace();
	  if(s[0] == '#' || s.length() == 0)
	    continue;

	  if((uid_t)uidFromName(QFile::encodeName(s)) == getuid()) {
	    access = TRUE;
	    fclose(f);
	    f = NULL;
	  }
	}
      }
      if(f)
	fclose(f);
    }

    if(!access) {
        QMessageBox::warning(0,"error",
		 QObject::tr("You're not allowed to dial out with "
		      "kppp.\nContact your system administrator."));
      return TEST_CRITICAL;
    }
  }

  // Test 1: search the pppd binary
  const char *f = pppdPath();

  if(!f) {
      QMessageBox::warning(0,"error",
		 QObject::tr("Cannot find the PPP daemon!\n"
                      "Make sure that pppd is installed."));
    warning++;
  }

  // Test 2: check access to the pppd binary
  if(f) {
#if 0
    if(access(f, X_OK) != 0 /* && geteuid() != 0 */) {
      KMessageBox::warning(0,
		   QObject::tr("You do not have the permission "
			"to start pppd!\n"
			"Contact your system administrator "
			"and ask to get access to pppd."));
      return TEST_CRITICAL;
    }
#endif

    if(geteuid() != 0) {
      struct stat st;
      stat(f, &st);
      if(st.st_uid != 0 || (st.st_mode & S_ISUID) == 0) {
          QMessageBox::warning(0,"error",
                     QObject::tr("You don't have sufficient permission to run\n"
                          "%1\n"
                          "Please make sure that kppp is owned by root "
                          "and has the SUID bit set.").arg(f));
        warning++;
      }
    }
  }

  // Test 5: check for existence of /etc/resolv.conf
  if (access(_PATH_RESCONF, R_OK) != 0) {
    QString file = _PATH_RESCONF" ";
    QString msgstr = QObject::tr("%1 is missing or can't be read!\n"
                   "Ask your system administrator to create "
                   "this file (can be empty) with appropriate "
                   "read and write permissions.").arg(file);
    QMessageBox::warning(0, "errror", msgstr);
    warning ++;
  }

  if(warning == 0)
    return TEST_OK;
  else
    return TEST_WARNING;
}
void FilePropsDialog::accept() {

  // applications
  if(mimeType && ui->openWith->isChanged()) {
    GAppInfo* currentApp = ui->openWith->selectedApp();
    g_app_info_set_as_default_for_type(currentApp, fm_mime_type_get_type(mimeType), NULL);
  }

  // check if chown or chmod is needed
  guint32 newUid = uidFromName(ui->owner->text());
  guint32 newGid = gidFromName(ui->ownerGroup->text());
  bool needChown = (newUid != -1 && newUid != uid) || (newGid != -1 && newGid != gid);

  int newOwnerPermSel = ui->ownerPerm->currentIndex();
  int newGroupPermSel = ui->groupPerm->currentIndex();
  int newOtherPermSel = ui->otherPerm->currentIndex();
  Qt::CheckState newExecCheckState = ui->executable->checkState();
  bool needChmod = ((newOwnerPermSel != ownerPermSel) ||
                    (newGroupPermSel != groupPermSel) ||
                    (newOtherPermSel != otherPermSel) ||
                    (newExecCheckState != execCheckState));

  if(needChmod || needChown) {
    FmPathList* paths = fm_path_list_new_from_file_info_list(fileInfos_);
    FileOperation* op = new FileOperation(FileOperation::ChangeAttr, paths);
    fm_path_list_unref(paths);
    if(needChown) {
      // don't do chown if new uid/gid and the original ones are actually the same.
      if(newUid == uid)
        newUid = -1;
      if(newGid == gid)
        newGid = -1;
      op->setChown(newUid, newGid);
    }
    if(needChmod) {
      mode_t newMode = 0;
      mode_t newModeMask = 0;
      // FIXME: we need to make sure that folders with "r" permission also have "x"
      // at the same time. Otherwise, it's not able to browse the folder later.
      if(newOwnerPermSel != ownerPermSel && newOwnerPermSel != ACCESS_NO_CHANGE) {
        // owner permission changed
        newModeMask |= (S_IRUSR|S_IWUSR); // affect user bits
        if(newOwnerPermSel == ACCESS_READ_ONLY)
          newMode |= S_IRUSR;
        else if(newOwnerPermSel == ACCESS_READ_WRITE)
          newMode |= (S_IRUSR|S_IWUSR);
      }
      if(newGroupPermSel != groupPermSel && newGroupPermSel != ACCESS_NO_CHANGE) {
        qDebug("newGroupPermSel: %d", newGroupPermSel);
        // group permission changed
        newModeMask |= (S_IRGRP|S_IWGRP); // affect group bits
        if(newGroupPermSel == ACCESS_READ_ONLY)
          newMode |= S_IRGRP;
        else if(newGroupPermSel == ACCESS_READ_WRITE)
          newMode |= (S_IRGRP|S_IWGRP);
      }
      if(newOtherPermSel != otherPermSel && newOtherPermSel != ACCESS_NO_CHANGE) {
        // other permission changed
        newModeMask |= (S_IROTH|S_IWOTH); // affect other bits
        if(newOtherPermSel == ACCESS_READ_ONLY)
          newMode |= S_IROTH;
        else if(newOtherPermSel == ACCESS_READ_WRITE)
          newMode |= (S_IROTH|S_IWOTH);
      }
      if(newExecCheckState != execCheckState && newExecCheckState != Qt::PartiallyChecked) {
        // executable state changed
        newModeMask |= (S_IXUSR|S_IXGRP|S_IXOTH);
        if(newExecCheckState == Qt::Checked)
          newMode |= (S_IXUSR|S_IXGRP|S_IXOTH);
      }
      op->setChmod(newMode, newModeMask);

      if(hasDir) { // if there are some dirs in our selected files
        QMessageBox::StandardButton r = QMessageBox::question(this,
                                          tr("Apply changes"),
                                          tr("Do you want to recursively apply these changes to all files and sub-folders?"),
                                          QMessageBox::Yes|QMessageBox::No);
        if(r == QMessageBox::Yes)
          op->setRecursiveChattr(true);
      }
    }
    op->setAutoDestroy(true);
    op->run();
  }

  QDialog::accept();
}