Changeset 444:ddaaf8e220bd in roaraudio for roard/roard.c
- Timestamp:
- 08/12/08 00:57:38 (16 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roard/roard.c
r440 r444 15 15 " --realtime - Trys to get realtime priority,\n" 16 16 " give multible times for being more realtime\n" 17 " --chroot DIR - chroots to the given dir\n" 18 " --setgid - GroupID to the audio group as specified via -G\n" 19 " --setuid - UserID to the audio user as specified via -U\n" 17 20 ); 18 21 … … 48 51 " -G GROUP - Sets the group for the UNIX Domain Socket, (default: audio)\n" 49 52 " You need the permittions to change the GID\n" 53 " -U USER - Sets the user for the UNIX Domain Socket, (default: do not set)\n" 54 " You need the permittions to change the UID (normaly only root has)\n" 50 55 " --no-listen - Do not listen for new clients (only usefull for relaing)\n" 51 56 " --client-fh - Comunicate with a client over this handle\n" … … 55 60 printf("\n"); 56 61 } 62 63 #define R_SETUID 1 64 #define R_SETGID 2 57 65 58 66 int main (int argc, char * argv[]) { … … 69 77 int port = ROAR_DEFAULT_PORT; 70 78 int drvid; 71 char * s_dev = NULL; 72 char * s_con = NULL; 73 char * s_opt = NULL; 74 int s_prim = 0; 75 char * sock_grp = "audio"; 76 struct group * grp; 79 char * s_dev = NULL; 80 char * s_con = NULL; 81 char * s_opt = NULL; 82 int s_prim = 0; 83 char * sock_grp = "audio"; 84 char * sock_user = NULL; 85 char * chrootdir = NULL; 86 int setids = 0; 87 struct group * grp = NULL; 88 struct passwd * pwd = NULL; 77 89 DRIVER_USERDATA_T drvinst; 78 90 struct roar_client * self = NULL; … … 135 147 } else if ( strcmp(k, "--realtime") == 0 ) { 136 148 realtime++; 149 } else if ( strcmp(k, "--chroot") == 0 ) { 150 chrootdir = argv[++i]; 151 } else if ( strcmp(k, "--setgid") == 0 ) { 152 setids |= R_SETGID; 153 } else if ( strcmp(k, "--setuid") == 0 ) { 154 setids |= R_SETUID; 137 155 138 156 } else if ( strcmp(k, "--list-cf") == 0 ) { … … 182 200 // ignore this case as it is the default behavor. 183 201 } else if ( strcmp(k, "-G") == 0 ) { 184 sock_grp = argv[++i]; 202 sock_grp = argv[++i]; 203 } else if ( strcmp(k, "-U") == 0 ) { 204 sock_user = argv[++i]; 185 205 186 206 } else if ( strcmp(k, "--no-listen") == 0 ) { … … 225 245 226 246 if ( *server == '/' ) { 247 if ( sock_user ) { 248 if ( (pwd = getpwnam(sock_user)) == NULL ) { 249 ROAR_ERR("Can not get UID for user %s: %s", sock_user, strerror(errno)); 250 } 251 } 227 252 if ( (grp = getgrnam(sock_grp)) == NULL ) { 228 253 ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno)); 229 254 } else { 230 chown(server, -1, grp->gr_gid); 255 if ( pwd ) { 256 chown(server, pwd->pw_uid, grp->gr_gid); 257 } else { 258 chown(server, -1, grp->gr_gid); 259 } 231 260 if ( getuid() == 0 ) 232 261 chmod(server, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP); … … 272 301 } 273 302 303 if ( setids & R_SETGID ) { 304 if ( setgroups(0, (const gid_t *) NULL) == -1 ) { 305 ROAR_ERR("Can not clear supplementary group IDs: %s", strerror(errno)); 306 } 307 if ( setgid(grp->gr_gid) == -1 ) { 308 ROAR_ERR("Can not set GroupID: %s", strerror(errno)); 309 } 310 } 311 274 312 275 313 clients_set_pid(g_self_client, getpid()); … … 294 332 } 295 333 334 if (chrootdir) { 335 if ( chroot(chrootdir) == -1 ) { 336 ROAR_ERR("Can not chroot to %s: %s", chrootdir, strerror(errno)); 337 return 2; 338 } 339 if ( chdir("/") == -1 ) { 340 ROAR_ERR("Can not chdir to /: %s", strerror(errno)); 341 return 2; 342 } 343 } 344 345 if ( setids & R_SETUID ) { 346 if ( !pwd || setuid(pwd->pw_uid) == -1 ) { 347 ROAR_ERR("Can not set UserID: %s", strerror(errno)); 348 return 3; 349 } 350 clients_set_uid(g_self_client, getuid()); 351 } 352 296 353 // start main loop... 297 354 main_loop(drvid, drvinst, &sa);
Note: See TracChangeset
for help on using the changeset viewer.