/*
============
Cmd_RemoteUnsetAdmin_f
============
*/
void SV_RemoteCmdUnsetAdmin(int uid, char* guid)
{

    adminPower_t *admin, **this;

    if(uid < 1){
            Com_Printf("No such player\n");
            return;
    }

    NV_ProcessBegin();

    for(this = &adminpower, admin = *this; admin ; admin = *this)
    {

        if(admin->uid == uid){
                *this = admin->next;
                Z_Free(admin);
                NV_ProcessEnd();
                Com_Printf( "User removed: uid: %i\n", uid);
                SV_PrintAdministrativeLog( "removed admin with uid: %i", uid);
                return;
        }
        this = &admin->next;
    }

    Com_Printf( "Error: No such user in database\n");
    NV_ProcessEnd();
}
/*
============
Cmd_RemoteUnsetAdmin_f
============
*/
void SV_RemoteCmdUnsetAdmin(int uid, char* guid)
{

    adminPower_t *admin, **this;

    if(SV_UseUids()){

        if(uid < 1){
            Com_Printf("No such player\n");
            return;
        }

        NV_ProcessBegin();

        for(this = &adminpower, admin = *this; admin ; admin = *this)
        {

            if(admin->uid == uid){
                *this = admin->next;
                Z_Free(admin);
                NV_ProcessEnd();
                Com_Printf( "User removed: uid: %i\n", uid);
                SV_PrintAdministrativeLog( "removed admin with uid: %i", uid);
                return;
            }
            this = &admin->next;
        }

    }else{

        if(guid && strlen(guid) == 32)
        {
            guid += 24;
        }
        if(!guid || strlen(guid) != 8)
        {
                Com_Printf("Error: No such player\n");
                return;
        }

        NV_ProcessBegin();
        for(this = &adminpower, admin = *this; admin ; admin = *this)
        {

            if(!Q_stricmp(admin->guid, guid)){
                *this = admin->next;
                Z_Free(admin);
                NV_ProcessEnd();
                Com_Printf( "User removed: guid: %s\n", guid);
                SV_PrintAdministrativeLog( "removed admin with guid: %s", guid);
                return;
            }
            this = &admin->next;
        }

    }

    Com_Printf( "Error: No such user in database\n");
    NV_ProcessEnd();
}
Example #3
0
void Auth_UnsetAdmin_f( void ) {

    const char* username;
    int i;
    authData_admin_t* user;

    if(Cmd_Argc() != 2) {
        Com_Printf("Usage: %s  < username >\n");
        return;
    }

    username = Cmd_Argv(1);

    NV_ProcessBegin();

    for(i = 0, user = auth_admins.admins; i < MAX_AUTH_ADMINS; i++, user++) {

        if(!Q_stricmp(user->username, username)) {
            Com_Printf("Removed %s from the list of admins\n", user->username);
            Com_Memset(user, 0, sizeof(authData_admin_t));
            NV_ProcessEnd();
            return;
        }
    }
    Com_Printf("No such admin: %s\n", username);
}
/*
============
Cmd_RemoteSetPermission
Changes minimum-PowerLevel of a command
============
*/
void SV_RemoteCmdSetPermission(char* command, int power)
{


    NV_ProcessBegin();
    if(Cmd_SetPower(command, power))
    {
        SV_PrintAdministrativeLog("changed required power of cmd: %s to new power: %i", command, power);
        Com_Printf("changed required power of cmd: %s to new power: %i\n", command, power);
    }else{
        Com_Printf("Failed to change power of cmd: %s Maybe this is not a valid command.\n", command);
    }
    NV_ProcessEnd();
}
void SV_RemoteCmdSetAdmin(int uid, char* guid, int power)
{

    adminPower_t *admin;
    adminPower_t *this;

    if(SV_UseUids()){

        if(uid < 1){
            Com_Printf("No such player\n");
            return;
        }

        NV_ProcessBegin();

        for(admin = adminpower ; admin ; admin = admin->next){
            if(admin->uid == uid){
                if(admin->power != power){
                    admin->power = power;

                    Com_Printf( "Admin power changed for: uid: %i to level: %i\n", uid, power);
                    SV_PrintAdministrativeLog( "changed power of admin with uid: %i to new power: %i", uid, power);
                }
                NV_ProcessEnd();
                return;
            }
        }

        this = Z_Malloc(sizeof(adminPower_t));
        if(this){
            this->uid = uid;
            this->power = power;
            this->next = adminpower;
            adminpower = this;
            Com_Printf( "Admin added: uid: %i level: %i\n", uid, power);
            SV_PrintAdministrativeLog( "added a new admin with uid: %i and power: %i", uid, power);
        }

    }else{

        if(guid && strlen(guid) == 32)
        {
            guid += 24;
        }
        if(!guid || strlen(guid) != 8)
        {
                Com_Printf("Error: No such player\n");
                return;
        }

        NV_ProcessBegin();

        for(admin = adminpower ; admin ; admin = admin->next)
        {
            if(!Q_stricmp(admin->guid, guid)){
                if(admin->power != power){
                    admin->power = power;

                    Com_Printf( "Admin power changed for: guid: %s to level: %i\n", guid, power);
                    SV_PrintAdministrativeLog( "changed power of admin with guid: %s to new power: %i", guid, power);
                }
                NV_ProcessEnd();
                return;
            }
        }

        this = Z_Malloc(sizeof(adminPower_t));
        if(this)
        {
            Q_strncpyz(this->guid, guid, sizeof(this->guid));
            this->power = power;
            this->next = adminpower;
            adminpower = this;
            Com_Printf( "Admin added: guid: %s level: %i\n", guid, power);
            SV_PrintAdministrativeLog( "added a new admin with guid: %s and power: %i", guid, power);
        }
    }

    NV_ProcessEnd();
}
Example #6
0
void Auth_SetAdmin_f( void ) {

    const char* username;
    const char* password;
    const char* sha256;
    byte buff[129];
    char salt[65];
    unsigned long size = sizeof(salt);
    int power, i,uid;
    authData_admin_t* user;
    authData_admin_t* free = NULL;
    mvabuf;


    if(Cmd_Argc() != 4) {
        Com_Printf("Usage: %s <username> <password> <power>\n", Cmd_Argv(0));
        Com_Printf( "Where username is loginname for this user\n" );
        Com_Printf( "Where password is the initial 6 characters long or longer password for this user which should get changed by the user on first login\n" );
        Com_Printf( "Where power is one of the following: Any number between 1 and 100\n" );
        return;
    }

    username = Cmd_Argv(1);
    password = Cmd_Argv(2);
    power = atoi(Cmd_Argv(3));

    if(!username || !*username || !password || strlen(password) < 6 || power < 1 || power > 100) {
        Com_Printf("Usage: %s <username> <password> <power>\n", Cmd_Argv(0));
        Com_Printf( "Where username is loginname for this user\n" );
        Com_Printf( "Where password is the initial 6 characters long or longer password for this user which should get changed by the user on first login\n" );
        Com_Printf( "Where power is one of the following: Any number between 1 and 100\n" );
        return;
    }

    NV_ProcessBegin();

    uid = ++auth_admins.maxUID;


    for(i = 0, user = auth_admins.admins; i < MAX_AUTH_ADMINS; i++, user++) {

        if(!Q_stricmp(user->username, username)) {
            Com_Printf("An admin with this username is already registered\n");
            return;
        }

        if(!free && !*user->username )
            free = user;
    }
    if(!free) {
        Com_Printf("Too many registered admins. Limit is: %d\n", MAX_AUTH_ADMINS);
        return;
    }

    Com_RandomBytes(buff, sizeof(buff));
    //Sec_BinaryToHex((char *)buff,sizeof(buff),salt,&size);
    Sec_HashMemory(SEC_HASH_SHA256,buff,sizeof(buff),salt,&size,qfalse);
    /*for(i = 0; i < sizeof(salt) -1; i++){
    	if(salt[i] > 126){
    	    salt[i] -= 125;
    	}
    	if(salt[i] < ' '){
    	    salt[i] += ' ';
    	}
    	if(salt[i] == ';')
    		salt[i]++;

    	if(salt[i] == '\\')
    		salt[i]++;

    	if(salt[i] == '%')
    		salt[i]++;

    	if(salt[i] == '"')
    		salt[i]++;

    }

    salt[sizeof(salt) -1] = 0;*/

    sha256 = Com_SHA256(va("%s.%s", password, salt));

    Q_strncpyz(free->username, username, sizeof(free->username));

    Com_Printf("Debug: 1:%s 2:%s\n", username, free->username);

    Q_strncpyz(free->sha256, sha256, sizeof(free->sha256));
    Q_strncpyz(free->salt, (char*)salt, sizeof(free->salt));
    //free->power = power; Instead:
    SV_RemoteCmdSetAdmin(uid, NULL, power);

    free->uid = uid;
    Com_Printf("Registered user with Name: %s Power: %d UID: %d\n", free->username, power, uid);
    NV_ProcessEnd();
}
Example #7
0
void Auth_ChangeAdminPassword( int uid,const char* oldPassword,const char* password ) {

    const char* sha256;
    byte buff[129];
    char salt[65];
    unsigned long size = sizeof(salt);
    authData_admin_t *user, *user2;
    int i;
    //int uid = -1;
    mvabuf;


    if(!password || strlen(password) < 6) {
        Com_Printf("Error: the new password must have at least 6 characters\n");
        return;
    }

    NV_ProcessBegin();

    for(i = 0, user2 = auth_admins.admins; i < MAX_AUTH_ADMINS; i++, user2++) {
        if(*user2->username && user2->uid == uid) {
            user = user2;
        }
    }
    if(user == NULL) {
        Com_Printf("Error: unknown admin @%d!\n",uid);
        return;
    }


    Com_RandomBytes(buff, sizeof(buff));

    Sec_HashMemory(SEC_HASH_SHA256,buff,sizeof(buff),salt,&size,qfalse);
    /*salt[sizeof(salt) -1] = 0; // Not needed

    for(i = 0; i < sizeof(salt) -1; i++){
    	if(salt[i] > 126){
    	    salt[i] -= 125;
    	}
    	if(salt[i] < ' '){
    	    salt[i] += ' ';
    	}
    	if(salt[i] == ';')
    		salt[i]++;

    	if(salt[i] == '\\')
    		salt[i]++;

    	if(salt[i] == '%')
    		salt[i]++;

    	if(salt[i] == '"')
    		salt[i]++;
    }*/

    sha256 = Com_SHA256(va("%s.%s", password, salt));

    Q_strncpyz(user->sha256, sha256, sizeof(user->sha256));
    Q_strncpyz(user->salt, (char *)salt, sizeof(user->salt));

    NV_ProcessEnd();

    Com_Printf("Password changed to: %s\n", password);
}