Coded for OpenBSD
This commit is contained in:
parent
b519f6c57f
commit
dd23185130
@ -45,6 +45,10 @@
|
||||
#include <syslog.h>
|
||||
#include <time.h>
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
#include "xmalloc.h"
|
||||
#include "mbuseradd.h"
|
||||
|
||||
@ -174,7 +178,15 @@ int main(int argc, char *argv[])
|
||||
struct passwd *pwent, *pwuser;
|
||||
struct group *gr;
|
||||
pid_t ppid;
|
||||
#if defined(__OpenBSD__)
|
||||
#define ARG_SIZE 60
|
||||
static char **s, buf[ARG_SIZE];
|
||||
size_t siz = 100;
|
||||
char **p;
|
||||
int mib[4];
|
||||
#else
|
||||
FILE *fp;
|
||||
#endif
|
||||
|
||||
if (argc != 5)
|
||||
Help();
|
||||
@ -221,29 +233,37 @@ int main(int argc, char *argv[])
|
||||
* Find out the name of our parent.
|
||||
*/
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
#if defined(__OpenBSD__)
|
||||
#define ARG_SIZE 60
|
||||
static char **s, buf[ARG_SIZE];
|
||||
size_t siz = 100;
|
||||
char **p;
|
||||
int mib[4];
|
||||
ppid = getppid();
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
/*
|
||||
* Systems that use sysctl to get process information
|
||||
*/
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC_ARGS;
|
||||
mib[2] = ppid;
|
||||
mib[3] = KERN_PROC_ARGV;
|
||||
if (sysctl(mib, 4, s, &siz, NULL, 0) == 0)
|
||||
break;
|
||||
if ((s = realloc(s, siz)) == NULL) {
|
||||
fprintf(stderr, "mbuseradd: no memory\n");
|
||||
exit(1);
|
||||
}
|
||||
if (sysctl(mib, 4, s, &siz, NULL, 0) == -1) {
|
||||
perror("");
|
||||
fprintf(stderr, "mbuseradd: sysctl call failed\n");
|
||||
exit(1);
|
||||
}
|
||||
buf[0] = '\0';
|
||||
s = malloc(size, sizeof(char *));
|
||||
for (p = s; *p != NULL; p++) {
|
||||
if (p != s)
|
||||
strlcat(buf, " ", sizeof(buf));
|
||||
strlcat(buf, *p, sizeof(buf));
|
||||
}
|
||||
fprintf("%s\n", buf);
|
||||
printf("%s\n", buf);
|
||||
parent = xstrcpy(buf);
|
||||
#else
|
||||
ppid = getppid();
|
||||
/*
|
||||
* Systems with /proc filesystem like Linux, FreeBSD
|
||||
*/
|
||||
snprintf(temp, PATH_MAX, "/proc/%d/cmdline", ppid);
|
||||
if ((fp = fopen(temp, "r")) == NULL) {
|
||||
fprintf(stderr, "mbuseradd: can't read %s\n", temp);
|
||||
@ -252,14 +272,14 @@ int main(int argc, char *argv[])
|
||||
fgets(temp, PATH_MAX-1, fp);
|
||||
fclose(fp);
|
||||
parent = xstrcpy(Basename(temp));
|
||||
#endif
|
||||
|
||||
if (strcmp((char *)"-mbnewusr", parent)) {
|
||||
fprintf(stderr, "mbpasswd: illegal parent\n");
|
||||
fprintf(stderr, "mbuseradd: illegal parent\n");
|
||||
free(temp);
|
||||
free(parent);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
memset(args, 0, sizeof(args));
|
||||
|
||||
|
Reference in New Issue
Block a user