示例#1
0
void Server::setUsers(QVariantList users)
{
    m_users = users;
    invokeOnPeer("setUsers", users);
    emit usersChanged(users);
    
}
示例#2
0
/*!
    Clears the model.
 */
void IrcUserModel::clear()
{
    Q_D(IrcUserModel);
    if (!d->userList.isEmpty()) {
        beginResetModel();
        d->userList.clear();
        endResetModel();
        emit namesChanged(QStringList());
        emit titlesChanged(QStringList());
        emit usersChanged(QList<IrcUser*>());
        emit countChanged(0);
        emit emptyChanged(true);
    }
}
示例#3
0
void UserManagerBackend::addUser(QString username, QString fullname, QString home, QString shell, QString group, QString password)
{
    qDebug() << "Starting addUser " << username;
    int gid = -1;
    QMap<int, Group>::Iterator it;
    
    for ( it = groupList.begin(); it != groupList.end(); ++it )
    {
	if (it->getGroupname() == group)
        {
            gid = it->getGid();
            break;
        }
    }
    userList[username] = User(username, home, shell, fullname, password, gid);
    
    emit usersChanged();
    qDebug() << "Finished addUser: " << username;
}
示例#4
0
bool UserManagerBackend::commit()
{
    
    //Process users
    QMap<QString, User>::Iterator userIt;

    QStringList args;
    
    for ( userIt = userList.begin(); userIt != userList.end(); ++userIt )
    {
	args.clear();
        switch(userIt->getStatus())
        {
            case 1:
                //Modify User
                qDebug() << "Modifying user " << userIt->getUsername();
		if ( ! chroot.isEmpty() )
		   args << chroot << "pw";
                args << "usermod";
                args << userIt->getUsername();
		// Only change home-dir on non-encrypted users
                if ( ! userIt->getEnc() ) {
                  args << "-d";
                  args << userIt->getHome();
		}
                args << "-s";
                args << userIt->getShell();
                args << "-c";
                args << userIt->getFullname();
		if ( ! chroot.isEmpty() )
		   QProcess::execute("chroot", args);
		else
		   QProcess::execute("pw", args);
                
                if (userIt->getPassword() != "")
                {
		    // Refuse to continue if we are trying to change PW
		    // On an encrypted users homedir
                    if ( userIt->getEnc() ) {
                      qDebug() << "Cannot change encrypted password: "******"Changing password: "******"/tmp/.XXXXXXXX");
  		    if ( rfile.open() ) {
       		      QTextStream stream( &rfile );
      		      stream << userIt->getClearPassword();
    		      rfile.close();
  		    }
		    if ( ! chroot.isEmpty() )
  		      system("cat " + rfile.fileName().toLatin1() + " | chroot " + chroot.toLatin1() + " pw usermod " + userIt->getUsername().toLatin1() + " -h 0 ");
		    else
  		      system("cat " + rfile.fileName().toLatin1() + " | pw usermod " + userIt->getUsername().toLatin1() + " -h 0 ");

  		    rfile.remove();
                }
                break;
            case 2:
	    {
                //Add User
                qDebug() << "Adding user " << userIt->getUsername();
		// Create the new home-directory
		if ( chroot.isEmpty() ) {
		   system("/usr/local/share/pcbsd/scripts/mkzfsdir.sh " + userIt->getHome().toLatin1() );
		   system("pw groupadd " + userIt->getUsername().toLatin1() );
		} else {
		   system("mkdir -p " + chroot.toLatin1() + "/" + userIt->getHome().toLatin1() + " 2>/dev/null" );
		   system("chroot " + chroot.toLatin1() + " ln -s /usr/home /home 2>/dev/null" );
		   system("chroot " + chroot.toLatin1() + " pw groupadd " + userIt->getUsername().toLatin1() );
		}

		if ( ! chroot.isEmpty() )
		   args << chroot << "pw";
                args << "useradd";
                args << userIt->getUsername();
                args << "-c";
                args << userIt->getFullname();
		args << "-m";
                args << "-d";
                args << userIt->getHome();
                args << "-s";
                args << userIt->getShell();
                if (userIt->getGid() != -1)
                {
                    args << "-g";
                    args << QString::number(userIt->getGid());
		} else {
                    args << "-g";
                    args << userIt->getUsername();
                }
                args << "-G";
                args << "operator";
		if ( ! chroot.isEmpty() )
		   QProcess::execute("chroot", args);
		else
		   QProcess::execute("pw", args);

    		QTemporaryFile nfile("/tmp/.XXXXXXXX");
  		if ( nfile.open() ) {
       		  QTextStream stream( &nfile );
      		  stream << userIt->getClearPassword();
    		  nfile.close();
  		}
		if ( ! chroot.isEmpty() )
  		  system("cat " + nfile.fileName().toLatin1() + " | chroot " + chroot.toLatin1() + " pw usermod " + userIt->getUsername().toLatin1() + " -h 0 ");
		else
  		  system("cat " + nfile.fileName().toLatin1() + " | pw usermod " + userIt->getUsername().toLatin1() + " -h 0 ");
  	        nfile.remove();

		if ( chroot.isEmpty() ) {
		   qDebug() << "Enabling Flash Plugin for " << userIt->getUsername();
		   QString flashCmd = "su " + userIt->getUsername() + " -c \"flashpluginctl on\"";
		   system(flashCmd.toLatin1());
		}

		// Set permissions
		if ( chroot.isEmpty() )
		   system("chown -R " + userIt->getUsername().toLatin1() +":" + userIt->getUsername().toLatin1() + " "  + userIt->getHome().toLatin1() );
		else
		   system("chroot " + chroot.toLatin1() + " chown -R " + userIt->getUsername().toLatin1() +":" + userIt->getUsername().toLatin1() + " "  + userIt->getHome().toLatin1() );

		// Are we enabling encryption?
		if ( userIt->getEnc() ) {
		   QProcess::execute("enable_user_pefs", QStringList() << userIt->getUsername() << userIt->getClearPassword() );

		}

                break;
	    }
            case 3:
                //Delete User
                qDebug() << "Deleting user " << userIt->getUsername();

                if(userIt->getEnc()) {
		  // Unmount PEFS
	  	  system("umount " + userIt->getHome().toLatin1() );
		}
		if ( ! chroot.isEmpty() )
		   args << chroot << "pw";
                args << "userdel";
                args << userIt->getUsername();
                if(userIt->getDeleteHome()) {
			args << "-r";
			system("/usr/local/share/pcbsd/scripts/rmzfsdir.sh " + userIt->getHome().toLatin1() );
		}
		if ( ! chroot.isEmpty() )
		   QProcess::execute("chroot", args);
		else
		   QProcess::execute("pw", args);
                break;
        }
    }
    refreshUsers();
    
    //Process groups
    QMap<int, Group>::Iterator groupIt;
 
    for ( groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt )
    {
	args.clear();
        switch(groupIt->getStatus())
        {
            case 1:
                //Modify Group
                qDebug() << "Modifying group " << groupIt->getGroupname();
		if ( ! chroot.isEmpty() )
		   args << chroot << "pw";
		args << "groupmod";
		args << groupIt->getGroupname();
		args << "-M";
		args << groupIt->getMembers().join(",");
		if ( ! chroot.isEmpty() )
		   QProcess::execute("chroot", args);
		else
		   QProcess::execute("pw", args);
                break;
            case 2:
                //Add Group
                qDebug() << "Adding group " << groupIt->getGroupname();
		if ( ! chroot.isEmpty() )
		   args << chroot << "pw";
                args << "groupadd";
                args << groupIt->getGroupname();
                args << "-M";
                args << groupIt->getMembers().join(",");
		if ( ! chroot.isEmpty() )
		   QProcess::execute("chroot", args);
		else
		   QProcess::execute("pw", args);
                break;
            case 3:
                //Delete Group
                qDebug() << "Deleting group " << groupIt->getGroupname();
		if ( ! chroot.isEmpty() )
		   args << chroot << "pw";
                args << "groupdel";
                args << groupIt->getGroupname();
		if ( ! chroot.isEmpty() )
		   QProcess::execute("chroot", args);
		else
		   QProcess::execute("pw", args);
                break;
	}
    }
    refreshGroups();
    emit groupsChanged();
    emit usersChanged();
    
    return true;
}
示例#5
0
void UserManagerBackend::deleteUser(QString username)
{
    userList[username].setDeleted();
    emit usersChanged();
}
示例#6
0
void UserManagerBackend::changePassword(QString username, QString password)
{
    qDebug() << "running changePassword()";
    userList[username].setPassword(password);
    emit usersChanged();
}