mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Merge pull request #911 from thejan2009/setgid-setuid
Split setgid and setuid, add privilege check [RFC]
This commit is contained in:
		
						commit
						4e660975a9
					
				
					 1 changed files with 9 additions and 1 deletions
				
			
		
							
								
								
									
										10
									
								
								sway/main.c
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								sway/main.c
									
										
									
									
									
								
							| 
						 | 
					@ -156,10 +156,18 @@ int main(int argc, char **argv) {
 | 
				
			||||||
			exit(EXIT_FAILURE);
 | 
								exit(EXIT_FAILURE);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (getuid() != geteuid() || getgid() != getegid()) {
 | 
							if (getuid() != geteuid() || getgid() != getegid()) {
 | 
				
			||||||
			if (setgid(getgid()) != 0 || setuid(getuid()) != 0) {
 | 
								if (setgid(getgid()) != 0) {
 | 
				
			||||||
				sway_log(L_ERROR, "Unable to drop root");
 | 
									sway_log(L_ERROR, "Unable to drop root");
 | 
				
			||||||
				exit(EXIT_FAILURE);
 | 
									exit(EXIT_FAILURE);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								if (setuid(getuid()) != 0) {
 | 
				
			||||||
 | 
									sway_log(L_ERROR, "Unable to drop root");
 | 
				
			||||||
 | 
									exit(EXIT_FAILURE);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (setuid(0) != -1) {
 | 
				
			||||||
 | 
								sway_log(L_ERROR, "Root privileges can be restored.");
 | 
				
			||||||
 | 
								exit(EXIT_FAILURE);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		char *socket_path = getenv("SWAYSOCK");
 | 
							char *socket_path = getenv("SWAYSOCK");
 | 
				
			||||||
		if (!socket_path) {
 | 
							if (!socket_path) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue