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