Example #1
0
void userdel_main(void)
{
  struct passwd *pwd = NULL;

  pwd = xgetpwnam(*toys.optargs);
  update_password("/etc/passwd", pwd->pw_name, NULL);
  update_password("/etc/shadow", pwd->pw_name, NULL);

  // delete the group named USER, and remove user from group.
  // could update_password() be used for this? 
  // not a good idea, as update_passwd() updates one entry at a time
  // in this case it will be modifying the files as many times the 
  // USER appears in group database files. So the customized version
  // of update_passwd() is here.
  update_groupfiles("/etc/group", *toys.optargs);
  update_groupfiles("/etc/gshadow", *toys.optargs);

  if (toys.optflags & FLAG_r) {
    char *arg[] = {"rm", "-fr", pwd->pw_dir, NULL, NULL};

    sprintf(toybuf, "/var/spool/mail/%s",pwd->pw_name);
    arg[3] = toybuf;
    xexec(arg);
  }
}
gboolean
passwd_change_password (PasswdHandler *passwd_handler,
                        const char    *new_password,
                        PasswdCallback cb,
                        const gpointer user_data)
{
        GError *error = NULL;

        passwd_handler->changing_password = TRUE;

        passwd_handler->new_password = new_password;
        passwd_handler->chpasswd_cb = cb;
        passwd_handler->chpasswd_cb_data = user_data;

        /* Stop passwd if an error occured and it is still running */
        if (passwd_handler->backend_state == PASSWD_STATE_ERR) {

                /* Stop passwd, free resources */
                stop_passwd (passwd_handler);
        }

        /* Check that the backend is still running, or that an error
         * has occured but it has not yet exited */
        if (passwd_handler->backend_pid == -1) {
                /* If it is not, re-run authentication */

                /* Spawn backend */
                stop_passwd (passwd_handler);

                if (!spawn_passwd (passwd_handler, &error)) {
                        g_warning ("%s", error->message);
                        g_error_free (error);

                        return FALSE;
                }

                /* Add current and new passwords to queue */
                authenticate (passwd_handler);
                update_password (passwd_handler);
        } else {
                /* Only add new passwords to queue */
                update_password (passwd_handler);
        }

        /* Pop new password through the backend.
         * If user has no password, popping the queue would output current
         * password, while 'passwd' is waiting for the new one. So wait for
         * io_watch_stdout() to remove current password from the queue,
         * and output the new one for us.
         */
        if (passwd_handler->current_password)
                io_queue_pop (passwd_handler->backend_stdin_queue, passwd_handler->backend_stdin);

        /* Our IO watcher should now handle the rest */

        return TRUE;
}
/* Called when the "Change password" dialog-button is clicked
 * Returns: TRUE if we want to keep the dialog running, FALSE otherwise */
static gboolean
passdlg_process_response (PasswordDialog *pdialog, gint response_id)
{

	if (response_id == GTK_RESPONSE_OK) {
		/* Set busy as this can be a long process */
		passdlg_set_busy (pdialog, TRUE);

		/* Stop passwd if an error occured and it is still running */
		if (pdialog->backend_state == PASSWD_STATE_ERR) {

			/* Stop passwd, free resources */
			stop_passwd (pdialog);
		}

		/* Check that the backend is still running, or that an error
		 * hass occured but it has not yet exited */
		if (pdialog->backend_pid == -1) {
			/* If it is not, re-run authentication */

			/* Spawn backend */
			if (!passdlg_spawn_passwd (pdialog)) {
				return TRUE;
			}

			/* Add current and new passwords to queue */
			authenticate (pdialog);
			update_password (pdialog);
		} else {
			/* Only add new passwords to queue */
			update_password (pdialog);

			/* Pop new password through the backend */
			io_queue_pop (pdialog->backend_stdin_queue, pdialog->backend_stdin);
		}

		/* Our IO watcher should now handle the rest */

		/* Keep the dialog running */
		return TRUE;
	}

	return FALSE;
}
Example #4
0
void Application::resetAllData()
{
    QString file = QString("%1/calaos.conf").arg(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
    QSettings settings(file, QSettings::IniFormat);
    settings.clear();
    settings.sync();
    update_username("*****@*****.**");
    update_password("demo");
    update_hostname("demo.calaos.fr");
    logout();
}
void groupdel_main(void)
{
  struct group *grp = xgetgrnam(toys.optargs[toys.optc-1]);
  char *entry = 0;

  // delete user from group
  if (toys.optc == 2) {
    int i, len = 0, found = 0;
    char *s;

    xgetpwnam(*toys.optargs);
    if (grp->gr_mem) for (i = 0; grp->gr_mem[i]; i++) {
      if (!found && !strcmp(*toys.optargs, grp->gr_mem[i])) found++;
      else len += strlen(grp->gr_mem[i]) + 1;
    }
    if (!found)
      error_exit("user '%s' not in group '%s'", *toys.optargs, toys.optargs[1]);

    entry = s = xmalloc(len);
    for (i = 0; grp->gr_mem[i]; ) {
      if (i) *(s++) = ',';
      s = stpcpy(s, grp->gr_mem[i]);
    }

  // delete group
  } else {
    struct passwd *pw;

    for (endpwent(); (pw = getpwent());)
      if (pw->pw_gid == grp->gr_gid) break;

    if (pw) error_exit("can't remove primary group of user '%s'", pw->pw_name);
    if (CFG_TOYBOX_FREE) endpwent();
  }

  update_password("/etc/group", grp->gr_name, entry);
  update_password("/etc/gshadow", grp->gr_name, entry);
  if (CFG_TOYBOX_FREE) free(entry);
}
Example #6
0
void Application::loadSettings()
{
    QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());

    QString cnuser, cnpass;
    HardwareUtils::Instance()->loadAuthKeychain(cnuser, cnpass);
    if (cnuser.isEmpty()) cnuser = "******";
    if (cnpass.isEmpty()) cnpass = "******";

    update_username(cnuser);
    update_password(cnpass);
    update_hostname(settings.value("calaos/host", "demo.calaos.fr").toString());

    favoritesList = settings.value("app/favorites").toList();
}
Example #7
0
void Application::login(QString user, QString pass, QString host)
{
    if (HardwareUtils::Instance()->getNetworkStatus() == HardwareUtils::NotConnected)
    {
        HardwareUtils::Instance()->showAlertMessage(tr("Network error"),
                                                    tr("No network connection found, "
                                                       "this application requires a "
                                                       "network connection to work."),
                                                    tr("Close"));
        return;
    }

    if (get_applicationStatus() != Common::NotConnected)
        return;

    update_username(user);
    update_password(pass);
    update_hostname(host);

    update_applicationStatus(Common::Loading);
    calaosConnect->login(user, pass, host);
}