_Bool done;
SOCTYP *soc;
+uid_t gid; //ccurrent group id
+uid_t uid; //ccurrent user id
struct addrinfo hints;
struct addrinfo *tobind;
int phase;
hints.ai_flags=HINTFLG;
hints.ai_socktype=SOCK_STREAM;
tobind=(struct addrinfo *)0;
+gid=getegid(); //let be back to root if needed
+uid=geteuid(); //to open device on < 1024 port
+if (setegid(getgid())<0)
+ (void) rou_core_dump("%s Unable to set the Egid to '%d' (error=<%s>",
+ OPEP,getgid(),strerror(errno));
+if (seteuid(getuid())<0)
+ (void) rou_core_dump("%s Unable to set the Euid to '%d' (error=<%s>",
+ OPEP,getuid(),strerror(errno));
phase=0;
proceed=true;
while (proceed==true) {
}
phase++;
}
+(void) setegid(gid); //recover the standard application
+(void) seteuid(uid); //uid:gid
return done;
#undef OPEP
}
childs=(pid_t)0;
bindings=(SOCPTR **)0;
+bindings=soc_mkbindinf(bindings,pro_smtp,"192.219.254.70","25",3);
bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.1","2525",3);
-bindings=soc_mkbindinf(bindings,pro_smtp,"192.219.254.70","2525",3);
bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.26","2626",1);
nbrbind=rou_nbrlist((void **)bindings);
phase=0;
//title display
static _Bool modopen; //boolean module open/close
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to change the current ID to an */
+/* application working ID */
+/* */
+/********************************************************/
+static uid_t getappid(char *appname,_Bool group)
+
+{
+#define OPEP "uniprc.c:getappid"
+
+uid_t id;
+char *fullname;
+struct stat bufstat;
+
+id=(uid_t)0;
+fullname=rou_apppath(appname);
+if (stat(fullname,&bufstat)<0)
+ (void) rou_alert(0,"%s Unable to get <%s> stat (bug?)",OPEP,fullname);
+else {
+ if (group==false)
+ id=bufstat.st_uid;
+ else
+ id=bufstat.st_gid;
+ }
+fullname=rou_freestr(fullname);
+return id;
+#undef OPEP
+}
/*
\f
*/
}
phase++;
}
-if (fullname!=(char *)0)
- (void) free(fullname);
+fullname=rou_freestr(fullname);
return done;
#undef OPEP
}
va_end(args);
}
/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to change the current ID (must be */
+/* root) to the application/program "owner:group" */
+/* */
+/********************************************************/
+void prc_chgid(char *appnom)
+
+{
+#define OPEP "uniprc.c:prc_chgid,"
+#define MSG \
+ "%s Unable to %s to '%d' (error=<%s> (cur u/g id='%d/%d',eid='%d/%d') bug?)"
+
+struct rlimit limites;
+
+(void) memset(&limites,'\000',sizeof(struct rlimit));
+if (getuid()==0) { /*is changing ID possible */
+ uid_t uid;
+ uid_t gid;
+
+ gid=getappid(appnom,true);
+ uid=getappid(appnom,false);
+ if (setegid(gid)<0)
+ (void) rou_alert(0,MSG,OPEP,"setegid",gid,
+ strerror(errno),
+ getuid(),getgid(),
+ geteuid(),getegid());
+ if (seteuid(uid)<0)
+ (void) rou_alert(0,MSG,OPEP,"seteuid",uid,
+ strerror(errno),
+ getuid(),getgid(),
+ geteuid(),getegid());
+ }
+if (getrlimit(RLIMIT_CORE,&limites)<0) {
+ (void) rou_alert(0,"%s getrlimit error='%s'",OPEP,strerror(errno));
+ }
+limites.rlim_cur=limites.rlim_max;
+if (setrlimit(RLIMIT_CORE,&limites)<0) {
+ (void) rou_alert(0,"%s setrlimit error='%s'",OPEP,strerror(errno));
+ }
+//to allow application core-dump
+(void) prctl(PR_SET_DUMPABLE,1,0,0,0);
+#undef OPEP
+}
+/*
^L
*/
/********************************************************/
//big trouble need to be investigated
extern void prc_allow_core_dump();
-//To do an on purpose application memory core dump
-//with an explication message
-extern void prc_core_dump(const char *fmt,...);
-
//routine to make sure all child process are out of
//zombie state
extern void prc_nozombie();
//procedure to put application in deamon mode
extern pid_t prc_divedivedive();
+//procedure to change the current id (root) to the application "owner"
+extern void prc_chgid(char *appnom);
+
//homework to be done before starting/stopping module.
extern int prc_modeuniprc(_Bool mode);