|
version 1.2.2.2, 2011/06/13 20:23:35
|
version 1.2.2.3, 2012/04/05 12:22:44
|
|
Line 12 terms:
|
Line 12 terms:
|
| All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
| Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
| |
|
| Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 | Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 |
| by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
| |
|
| Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
|
Line 46 SUCH DAMAGE.
|
Line 46 SUCH DAMAGE.
|
| #include "global.h" |
#include "global.h" |
| |
|
| |
|
| sl_config cfg; | cfg_root_t cfg; |
| int Verbose, Timeout, kq; |
int Verbose, Timeout, kq; |
| char szUser[MAX_STR], szMount[MAXPATHLEN], szDev[MAXPATHLEN], | ait_val_t User, Mount, Dev, Chroot; |
| szChroot[MAXPATHLEN], szSess[MAXPATHLEN], szConfig[MAXPATHLEN]; | char szSess[MAXPATHLEN], szConfig[MAXPATHLEN]; |
| extern char compiled[], compiledby[], compilehost[]; |
extern char compiled[], compiledby[], compilehost[]; |
| |
|
| |
|
| static void Usage() | static void |
| | Usage() |
| { |
{ |
| |
|
| printf( "CFExec is tool for managment R/W operation with CompactFlash\n" |
printf( "CFExec is tool for managment R/W operation with CompactFlash\n" |
|
Line 68 static void Usage()
|
Line 69 static void Usage()
|
| "\n", compiled, compiledby, compilehost); |
"\n", compiled, compiledby, compilehost); |
| } |
} |
| |
|
| static int update(int flags) | static int |
| | update(int flags) |
| { |
{ |
| struct ufs_args mnt; |
struct ufs_args mnt; |
| |
|
| memset(&mnt, 0, sizeof mnt); |
memset(&mnt, 0, sizeof mnt); |
| mnt.fspec = szDev; | mnt.fspec = AIT_GET_STR(&Dev); |
| #ifdef __NetBSD__ |
#ifdef __NetBSD__ |
| if (mount("ufs", szMount, flags, &mnt, sizeof mnt) == -1) { | if (mount("ufs", AIT_GET_STR(&Mount), flags, &mnt, sizeof mnt) == -1) { |
| #else |
#else |
| if (mount("ufs", szMount, flags, &mnt) == -1) { | if (mount("ufs", AIT_GET_STR(&Mount), flags, &mnt) == -1) { |
| #endif |
#endif |
| printf("Error:: can`t update mount %s #%d - %s\n", szMount, errno, strerror(errno)); | printf("Error:: can`t update mount %s #%d - %s\n", AIT_GET_STR(&Mount), |
| | errno, strerror(errno)); |
| return -1; |
return -1; |
| } |
} |
| |
|
| VERB(5) printf("Info(5):: safe mount for device %s to %s operation (%s)\n", |
VERB(5) printf("Info(5):: safe mount for device %s to %s operation (%s)\n", |
| szDev, szMount, (flags & MNT_RDONLY) ? "ro" : "rw"); | AIT_GET_STR(&Dev), AIT_GET_STR(&Mount), (flags & MNT_RDONLY) ? "ro" : "rw"); |
| return 0; |
return 0; |
| } |
} |
| |
|
| static void setuser() | static void |
| | setuser() |
| { |
{ |
| struct passwd *pw; |
struct passwd *pw; |
| |
|
| pw = getpwnam(szUser); | pw = getpwnam(AIT_GET_LIKE(&User, char*)); |
| if (pw) { |
if (pw) { |
| setuid(pw->pw_uid); |
setuid(pw->pw_uid); |
| setgid(pw->pw_gid); |
setgid(pw->pw_gid); |
| endpwent(); |
endpwent(); |
| |
|
| VERB(5) printf("Info(5):: Suid to user %s.\n", szUser); | VERB(5) printf("Info(5):: Suid to user %s.\n", AIT_GET_STR(&User)); |
| } else |
} else |
| VERB(5) printf("Info(5):: Can`t suid to user %s !\n", szUser); | VERB(5) printf("Info(5):: Can`t suid to user %s !\n", AIT_GET_STR(&User)); |
| } |
} |
| |
|
| static int mkevent(struct kevent *chg, struct kevent *evt) | static int |
| | mkevent(struct kevent *chg, struct kevent *evt) |
| { |
{ |
| int f; |
int f; |
| char szStr[MAX_STR]; |
char szStr[MAX_STR]; |
|
Line 129 static int mkevent(struct kevent *chg, struct kevent *
|
Line 134 static int mkevent(struct kevent *chg, struct kevent *
|
| memset(chg, 0, sizeof(struct kevent)); |
memset(chg, 0, sizeof(struct kevent)); |
| memset(evt, 0, sizeof(struct kevent)); |
memset(evt, 0, sizeof(struct kevent)); |
| |
|
| EV_SET(chg, f, EVFILT_VNODE, EV_ADD, NOTE_DELETE | NOTE_RENAME | NOTE_REVOKE, 0, (intptr_t) NULL); | EV_SET(chg, f, EVFILT_VNODE, EV_ADD, NOTE_DELETE | NOTE_RENAME | NOTE_REVOKE, |
| | 0, (intptr_t) NULL); |
| } |
} |
| |
|
| return f; |
return f; |
| } |
} |
| |
|
| // --------------------------------- | static void |
| | cleanexit() |
| | { |
| | AIT_FREE_VAL(&User); |
| | AIT_FREE_VAL(&Dev); |
| | AIT_FREE_VAL(&Mount); |
| | AIT_FREE_VAL(&Chroot); |
| |
|
| int main(int argc, char **argv) | cfgUnloadConfig(&cfg); |
| | } |
| | |
| | |
| | int |
| | main(int argc, char **argv) |
| { |
{ |
| char ch; |
char ch; |
| const char *err = NULL; |
const char *err = NULL; |
|
Line 145 int main(int argc, char **argv)
|
Line 162 int main(int argc, char **argv)
|
| struct timespec ts; |
struct timespec ts; |
| pid_t pid; |
pid_t pid; |
| int f, stat = 0; |
int f, stat = 0; |
| // sigset_t sig, oldsig; |
|
| |
|
| strlcpy(szConfig, DEFAULT_CONFIG, MAXPATHLEN); |
strlcpy(szConfig, DEFAULT_CONFIG, MAXPATHLEN); |
| // Load variables from config if exists | /* Load variables from config if exists */ |
| if (!LoadConfig(szConfig, &cfg)) { | if (!cfgLoadConfig(szConfig, &cfg)) { |
| cfg_LoadAttribute(&cfg, CFG("cfexec"), CFG("timeout"), CFG(szUser), MAX_STR, DEFAULT_TIMEOUT); | cfg_loadAttribute(&cfg, "cfexec", "timeout", &User, DEFAULT_TIMEOUT); |
| #ifndef HAVE_STRTONUM |
#ifndef HAVE_STRTONUM |
| Timeout = (int) strtol(szUser, NULL, 0); |
Timeout = (int) strtol(szUser, NULL, 0); |
| #else |
#else |
| Timeout = strtonum(szUser, 0, 3600, &err); | Timeout = strtonum(AIT_GET_STR(&User), 0, 3600, &err); |
| #endif |
#endif |
| |
AIT_FREE_VAL(&User); |
| if (!Timeout && err) { |
if (!Timeout && err) { |
| printf("Error:: in seconds for timeout %s - %s\n", optarg, err); |
printf("Error:: in seconds for timeout %s - %s\n", optarg, err); |
| UnloadConfig(&cfg); | cfgUnloadConfig(&cfg); |
| return 1; |
return 1; |
| } |
} |
| cfg_LoadAttribute(&cfg, CFG("cfexec"), CFG("suid"), CFG(szUser), MAX_STR, DEFAULT_USER); | cfg_loadAttribute(&cfg, "cfexec", "suid", &User, DEFAULT_USER); |
| cfg_LoadAttribute(&cfg, CFG("cfexec"), CFG("mount"), CFG(szMount), MAXPATHLEN, DEFAULT_MOUNT); | cfg_loadAttribute(&cfg, "cfexec", "mount", &Mount, DEFAULT_MOUNT); |
| cfg_LoadAttribute(&cfg, CFG("cfexec"), CFG("device"), CFG(szDev), MAXPATHLEN, DEFAULT_DEVICE); | cfg_loadAttribute(&cfg, "cfexec", "device", &Dev, DEFAULT_DEVICE); |
| cfg_LoadAttribute(&cfg, CFG("cfexec"), CFG("chroot"), CFG(szChroot), MAXPATHLEN, DEFAULT_CHROOT); | cfg_loadAttribute(&cfg, "cfexec", "chroot", &Chroot, DEFAULT_CHROOT); |
| |
|
| UnloadConfig(&cfg); | cfgUnloadConfig(&cfg); |
| } else { |
} else { |
| Timeout = atoi(DEFAULT_TIMEOUT); |
Timeout = atoi(DEFAULT_TIMEOUT); |
| strlcpy(szUser, DEFAULT_USER, MAX_STR); | AIT_SET_STR(&User, DEFAULT_USER); |
| strlcpy(szMount, DEFAULT_MOUNT, MAXPATHLEN); | AIT_SET_STR(&Mount, DEFAULT_MOUNT); |
| strlcpy(szDev, DEFAULT_DEVICE, MAXPATHLEN); | AIT_SET_STR(&Dev, DEFAULT_DEVICE); |
| strlcpy(szChroot, DEFAULT_CHROOT, MAXPATHLEN); | AIT_SET_STR(&Chroot, DEFAULT_CHROOT); |
| } |
} |
| |
|
| // Load variables from arguments if exists | atexit(cleanexit); |
| | |
| | /* Load variables from arguments if exists */ |
| while ((ch = getopt(argc, argv, "hvu:c:d:m:t:")) != -1) |
while ((ch = getopt(argc, argv, "hvu:c:d:m:t:")) != -1) |
| switch (ch) { |
switch (ch) { |
| case 'v': |
case 'v': |
| Verbose++; |
Verbose++; |
| break; |
break; |
| case 'u': |
case 'u': |
| strlcpy(szUser, optarg, MAX_STR); | AIT_SET_STR(&User, optarg); |
| break; |
break; |
| case 'c': |
case 'c': |
| strlcpy(szChroot, optarg, MAXPATHLEN); | AIT_SET_STR(&Chroot, optarg); |
| break; |
break; |
| case 'd': |
case 'd': |
| strlcpy(szDev, optarg, MAXPATHLEN); | AIT_SET_STR(&Dev, optarg); |
| break; |
break; |
| case 'm': |
case 'm': |
| strlcpy(szMount, optarg, MAXPATHLEN); | AIT_SET_STR(&Mount, optarg); |
| break; |
break; |
| case 't': |
case 't': |
| #ifndef HAVE_STRTONUM |
#ifndef HAVE_STRTONUM |
| Timeout = (int) strtol(szUser, NULL, 0); | Timeout = (int) strtol(optarg, NULL, 0); |
| #else |
#else |
| Timeout = strtonum(optarg, 0, 3600, &err); |
Timeout = strtonum(optarg, 0, 3600, &err); |
| #endif |
#endif |
|
Line 214 int main(int argc, char **argv)
|
Line 233 int main(int argc, char **argv)
|
| argv += optind; |
argv += optind; |
| |
|
| memset(szSess, 0, MAXPATHLEN); |
memset(szSess, 0, MAXPATHLEN); |
| snprintf(szSess, MAXPATHLEN, "%s%s-cfexec.LCK", DEFAULT_TMP, szMount); | snprintf(szSess, MAXPATHLEN, "%s%s-cfexec.LCK", DEFAULT_TMP, AIT_GET_STR(&Mount)); |
| |
|
| VERB(3) printf("Info(3):: Chroot=%s SUID=%s Device=%s Mount=%s Timeout=%d Session=%s\n", |
VERB(3) printf("Info(3):: Chroot=%s SUID=%s Device=%s Mount=%s Timeout=%d Session=%s\n", |
| szChroot, szUser, szDev, szMount, Timeout, szSess); | AIT_GET_STR(&Chroot), AIT_GET_STR(&User), AIT_GET_STR(&Dev), |
| | AIT_GET_STR(&Mount), Timeout, szSess); |
| |
|
| if (!access(szSess, F_OK)) { |
if (!access(szSess, F_OK)) { |
| printf("cfexec already running ...\n"); |
printf("cfexec already running ...\n"); |
|
Line 281 int main(int argc, char **argv)
|
Line 301 int main(int argc, char **argv)
|
| return 5; |
return 5; |
| case 0: |
case 0: |
| VERB(5) printf("Go to running process %s\n", *argv); |
VERB(5) printf("Go to running process %s\n", *argv); |
| if (chroot(szChroot) == -1) { | if (chroot(AIT_GET_STR(&Chroot)) == -1) { |
| printf("Error:: can`t chroot to dir %s #%d - %s\n", |
printf("Error:: can`t chroot to dir %s #%d - %s\n", |
| szChroot, errno, strerror(errno)); | AIT_GET_STR(&Chroot), errno, strerror(errno)); |
| } else { |
} else { |
| if (strncmp(szUser, "root", 5)) | if (strncmp(AIT_GET_STR(&User), "root", 5)) |
| setuser(); |
setuser(); |
| |
|
| /* chdir("/"); */ |
/* chdir("/"); */ |
| execvp(*argv, argv); |
execvp(*argv, argv); |
| } |
} |
| _exit(127); | exit(127); |
| break; |
break; |
| default: |
default: |
| waitpid(pid, &stat, 0); |
waitpid(pid, &stat, 0); |
|
Line 302 int main(int argc, char **argv)
|
Line 322 int main(int argc, char **argv)
|
| if (update(MNT_UPDATE | MNT_RDONLY) == -1) |
if (update(MNT_UPDATE | MNT_RDONLY) == -1) |
| return 8; |
return 8; |
| } |
} |
| |
|
| // sigprocmask(SIG_SETMASK, &oldsig, NULL); |
|
| } |
} |
| |
|
| return stat; |
return stat; |