File: cmdkill.c

package info (click to toggle)
xshipwars 1.32-5
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,176 kB
  • ctags: 6,357
  • sloc: ansic: 157,152; makefile: 226; sh: 75
file content (77 lines) | stat: -rw-r--r-- 1,878 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "swserv.h"
 
  
/*
 *      Kills a process.
 */
int CmdKill(int condescriptor, char *arg)
{
        char sndbuf[CS_DATA_MAX_LEN]; 
        register char can_kill_others;
        register int uid;
        long object_num; 
        int schedual_num;
        
        if(arg == NULL)
            return(-1);
        
        if(strlen(arg) < 1)
        {
            sprintf(sndbuf, "Usage: `kill <pid>'");   
            NetSendLiveMessage(condescriptor, sndbuf);
            
            return(-1);
        }
         
        
        /* Get object number. */
        object_num = connection[condescriptor]->object_num;
        if(DBIsObjectGarbage(object_num))
            return(-1);
        
        /* Get object's uid. */
        uid = xsw_object[object_num]->permission.uid;

        /* Check if connection can kill processes of others. */
        can_kill_others = (uid > ACCESS_UID_PSKILLO) ? 0 : 1;
  
 
        /* Get schedual number as PID. */
        schedual_num = atoi(arg);
 
        
        /* Does PID exist? */
        if(!SchedualIsActive(schedual_num))
        {
            sprintf(sndbuf, "%i: No such pid.",
                schedual_num
            );
            NetSendLiveMessage(condescriptor, sndbuf);
        
            return(-2);
        }
        if((schedual[schedual_num]->run_owner != object_num) &&
           !can_kill_others
        )   
        {
            sprintf(sndbuf, "%i: You do not own that PID.",
                schedual_num
            );
            NetSendLiveMessage(condescriptor, sndbuf);
        
            return(-2);
        }


        /* Recycle the schedual (effectively killing the PID). */
        SchedualRecycle(schedual_num);
        sprintf(sndbuf,
            "%i: Process killed.",
            schedual_num
        );
        NetSendLiveMessage(condescriptor, sndbuf);


        return(0);
}