aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorDavid M. Syzdek <david.syzdek@acsalaska.com>2020-02-10 12:56:12 -0900
committerDavid M. Syzdek <david.syzdek@acsalaska.com>2020-02-10 12:56:12 -0900
commit9c8fb98b46b0ba928c3288e87be6bfe5b8a150c5 (patch)
treeeb378b33e15c040a879611b9cb8fa4989c9b8c3a /src
parent693a74cf36fcb7c99c77dae40091ea1717a091d7 (diff)
downloadakcom-udpecho-9c8fb98b46b0ba928c3288e87be6bfe5b8a150c5.tar.gz
akcom-udpecho-9c8fb98b46b0ba928c3288e87be6bfe5b8a150c5.tar.bz2
akcom-udpecho-9c8fb98b46b0ba928c3288e87be6bfe5b8a150c5.tar.xz
akcom-udpecho-9c8fb98b46b0ba928c3288e87be6bfe5b8a150c5.zip
akcom-udpechod: replacing uid struct member with static variable
Diffstat (limited to 'src')
-rw-r--r--src/akcom-udpechod.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/akcom-udpechod.c b/src/akcom-udpechod.c
index c78e020..984efb8 100644
--- a/src/akcom-udpechod.c
+++ b/src/akcom-udpechod.c
@@ -148,12 +148,10 @@ static int should_stop = 0;
148 148
149struct app_config 149struct app_config
150{ 150{
151 uid_t uid; // setuid
152 gid_t gid; // setgid 151 gid_t gid; // setgid
153}; 152};
154static struct app_config cnf = 153static struct app_config cnf =
155{ 154{
156 .uid = 0,
157 .gid = 0, 155 .gid = 0,
158}; 156};
159static const char * prog_name = "a.out"; 157static const char * prog_name = "a.out";
@@ -166,6 +164,7 @@ static int32_t cnf_verbose = 0; // runt
166static int cnf_facility = LOG_DAEMON; // syslog facility 164static int cnf_facility = LOG_DAEMON; // syslog facility
167static int cnf_dont_fork = 0; 165static int cnf_dont_fork = 0;
168static const char * cnf_listen = NULL; // IP address to listen for requests 166static const char * cnf_listen = NULL; // IP address to listen for requests
167static uid_t cnf_uid = 0; // setuid
169 168
170 169
171////////////////// 170//////////////////
@@ -350,7 +349,7 @@ int main(int argc, char * argv[])
350 fprintf(stderr, "%s: getpwnam(): %s\n", prog_name, strerror(errno)); 349 fprintf(stderr, "%s: getpwnam(): %s\n", prog_name, strerror(errno));
351 return(1); 350 return(1);
352 }; 351 };
353 cnf.uid = pw->pw_uid; 352 cnf_uid = pw->pw_uid;
354 break; 353 break;
355 354
356 case 'v': 355 case 'v':
@@ -373,13 +372,13 @@ int main(int argc, char * argv[])
373 372
374 // set defaults for setuid/setgid 373 // set defaults for setuid/setgid
375 cnf.gid = (cnf.gid == 0) ? getgid() : cnf.gid; 374 cnf.gid = (cnf.gid == 0) ? getgid() : cnf.gid;
376 cnf.uid = (cnf.uid == 0) ? getuid() : cnf.uid; 375 cnf_uid = (cnf_uid == 0) ? getuid() : cnf_uid;
377 if ( (cnf.gid != getgid()) && (getuid() != 0) ) 376 if ( (cnf.gid != getgid()) && (getuid() != 0) )
378 { 377 {
379 fprintf(stderr, "%s: setgid requires root access\n", prog_name); 378 fprintf(stderr, "%s: setgid requires root access\n", prog_name);
380 return(1); 379 return(1);
381 }; 380 };
382 if ( (cnf.uid != getuid()) && (getuid() != 0) ) 381 if ( (cnf_uid != getuid()) && (getuid() != 0) )
383 { 382 {
384 fprintf(stderr, "%s: setuid requires root access\n", prog_name); 383 fprintf(stderr, "%s: setuid requires root access\n", prog_name);
385 return(1); 384 return(1);
@@ -518,10 +517,10 @@ int my_daemonize(void)
518 close(fd); 517 close(fd);
519 return(-1); 518 return(-1);
520 }; 519 };
521 if ( (cnf.uid != getuid()) || 520 if ( (cnf_uid != getuid()) ||
522 (cnf.gid != getgid()) ) 521 (cnf.gid != getgid()) )
523 { 522 {
524 if ((rc = fchown(fd, cnf.uid, cnf.gid)) == -1) 523 if ((rc = fchown(fd, cnf_uid, cnf.gid)) == -1)
525 { 524 {
526 my_error("fchown(): %s", strerror(errno)); 525 my_error("fchown(): %s", strerror(errno));
527 close(fd); 526 close(fd);
@@ -634,7 +633,7 @@ int my_daemonize(void)
634 unlink(cnf_pidfile); 633 unlink(cnf_pidfile);
635 return(-1); 634 return(-1);
636 }; 635 };
637 if ( (getuid() != cnf.uid) && ((rc = setreuid(cnf.uid, cnf.uid)) == -1) ) 636 if ( (getuid() != cnf_uid) && ((rc = setreuid(cnf_uid, cnf_uid)) == -1) )
638 { 637 {
639 my_error("getuid(): %s", strerror(errno)); 638 my_error("getuid(): %s", strerror(errno));
640 close(s); 639 close(s);