OrionUserland
Barry Using POSIX names in structs 2e11092 (2 years, 4 months ago)diff --git a/init/main.c b/init/main.c index 0eb2b3b..dc8b70b 100644 --- a/init/main.c +++ b/init/main.c @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) { if (getpid() != 1) { - printf("init will not run except as PID#1"); + printf("init will not run except as PID#1\n"); abort(); } diff --git a/login/main.c b/login/main.c index d1bfd55..292901a 100644 --- a/login/main.c +++ b/login/main.c @@ -34,7 +34,7 @@ main(int argc, char *argv[]) if (sz < 1) continue; - pwd = getpwname(input); + pwd = getpwnam(input); if (!pwd) continue; @@ -42,7 +42,7 @@ main(int argc, char *argv[]) memset(input, 0, 1024); ioctl(STDIN_FILENO, TCGETS, &tcold); memcpy(&tcnew, &tcold, sizeof(Termios)); - tcnew.lflag &= ~ECHO; + tcnew.c_lflag &= ~ECHO; ioctl(STDIN_FILENO, TCSETS, &tcnew); #ifdef MANUAL_LOGIN sz = read(STDIN_FILENO, input, 1024); @@ -56,19 +56,20 @@ main(int argc, char *argv[]) continue; ioctl(STDIN_FILENO, TCSETS, &tcold); - if (!strcmp(input, pwd->password)) + if (!strcmp(input, pwd->pw_passwd)) break; printf("Login incorrect\n"); } printf("\n"); dbgprintf("Authenticating \"%s\" (%d:%d) -> \"%s\" @ \"%s\"", - pwd->username, pwd->uid, pwd->gid, pwd->shell, pwd->homedir); - chdir(pwd->homedir); - setuid(pwd->uid); - setgid(pwd->gid); + pwd->pw_name, pwd->pw_uid, pwd->pw_gid, pwd->pw_shell, + pwd->pw_dir); + chdir(pwd->pw_dir); + setuid(pwd->pw_uid); + setgid(pwd->pw_gid); char *v[] = { "sh", NULL }; - execve(pwd->shell, v, NULL); + execve(pwd->pw_shell, v, NULL); return 0; } diff --git a/ls/main.c b/ls/main.c index 27b754c..54fab25 100644 --- a/ls/main.c +++ b/ls/main.c @@ -93,9 +93,9 @@ print_normal(Result *head) next = curr->next; int executable = 0; - if ((curr->stat.mode & S_IXUSR) - || (curr->stat.mode & S_IXGRP) - || (curr->stat.mode & S_IXOTH)) + if ((curr->stat.st_mode & S_IXUSR) + || (curr->stat.st_mode & S_IXGRP) + || (curr->stat.st_mode & S_IXOTH)) executable = 1; if (curr->type == DT_DIR) @@ -134,26 +134,26 @@ print_long(Result *head) size_t total = 0; int linkWidth = 0, unameWidth = 0, groupWidth = 0, sizeWidth = 0; for (curr = head; curr; curr = curr->next) { - int linkTmp = curr->stat.nlink, linkWidthTmp = 1; + int linkTmp = curr->stat.st_nlink, linkWidthTmp = 1; while (linkTmp /= 10) linkWidthTmp++; if (linkWidthTmp > linkWidth) linkWidth = linkWidthTmp; - Passwd *pwd = getpwuid(curr->stat.uid); - if (strlen(pwd->username) > unameWidth) - unameWidth = strlen(pwd->username); - Group *grp = getgrgid(curr->stat.gid); - if (strlen(grp->name) > groupWidth) - groupWidth = strlen(grp->name); + Passwd *pwd = getpwuid(curr->stat.st_uid); + if (strlen(pwd->pw_name) > unameWidth) + unameWidth = strlen(pwd->pw_name); + Group *grp = getgrgid(curr->stat.st_gid); + if (strlen(grp->gr_name) > groupWidth) + groupWidth = strlen(grp->gr_name); - int sizeTmp = curr->stat.size, sizeWidthTmp = 1; + int sizeTmp = curr->stat.st_size, sizeWidthTmp = 1; while (sizeTmp /= 10) sizeWidthTmp++; if (sizeWidthTmp > sizeWidth) sizeWidth = sizeWidthTmp; - total += (curr->stat.size + (1024 - 1)) / 1024; + total += (curr->stat.st_size + (1024 - 1)) / 1024; } /* Print out */ @@ -167,27 +167,27 @@ print_long(Result *head) char uname[33], group[33]; int executable = 0; perm[0] = type[curr->type]; - perm[1] = (curr->stat.mode & S_IRUSR) ? 'r' : '-'; - perm[2] = (curr->stat.mode & S_IWUSR) ? 'w' : '-'; - perm[3] = (curr->stat.mode & S_IXUSR) ? 'x' : '-'; - perm[4] = (curr->stat.mode & S_IRGRP) ? 'r' : '-'; - perm[5] = (curr->stat.mode & S_IWGRP) ? 'w' : '-'; - perm[6] = (curr->stat.mode & S_IXGRP) ? 'x' : '-'; - perm[7] = (curr->stat.mode & S_IROTH) ? 'r' : '-'; - perm[8] = (curr->stat.mode & S_IWOTH) ? 'w' : '-'; - perm[9] = (curr->stat.mode & S_IXOTH) ? 'x' : '-'; - Passwd *pwd = getpwuid(curr->stat.uid); - Group *grp = getgrgid(curr->stat.gid); - if ((curr->stat.mode & S_IXUSR) - || (curr->stat.mode & S_IXGRP) - || (curr->stat.mode & S_IXOTH)) + perm[1] = (curr->stat.st_mode & S_IRUSR) ? 'r' : '-'; + perm[2] = (curr->stat.st_mode & S_IWUSR) ? 'w' : '-'; + perm[3] = (curr->stat.st_mode & S_IXUSR) ? 'x' : '-'; + perm[4] = (curr->stat.st_mode & S_IRGRP) ? 'r' : '-'; + perm[5] = (curr->stat.st_mode & S_IWGRP) ? 'w' : '-'; + perm[6] = (curr->stat.st_mode & S_IXGRP) ? 'x' : '-'; + perm[7] = (curr->stat.st_mode & S_IROTH) ? 'r' : '-'; + perm[8] = (curr->stat.st_mode & S_IWOTH) ? 'w' : '-'; + perm[9] = (curr->stat.st_mode & S_IXOTH) ? 'x' : '-'; + Passwd *pwd = getpwuid(curr->stat.st_uid); + Group *grp = getgrgid(curr->stat.st_gid); + if ((curr->stat.st_mode & S_IXUSR) + || (curr->stat.st_mode & S_IXGRP) + || (curr->stat.st_mode & S_IXOTH)) executable = 1; printf("%s %*d %*s %*s %*d ", perm, - linkWidth, curr->stat.nlink, - -unameWidth, pwd->username, - -groupWidth, grp->name, - sizeWidth, curr->stat.size); + linkWidth, curr->stat.st_nlink, + -unameWidth, pwd->pw_name, + -groupWidth, grp->gr_name, + sizeWidth, curr->stat.st_size); if (curr->type == DT_DIR) printf("\033[1;34m%s\033[0m\n", curr->name); @@ -232,7 +232,7 @@ ls(char *name) } stat(name, &statbuf); - if (!S_ISDIR(statbuf.mode)) { + if (!S_ISDIR(statbuf.st_mode)) { close(fd); return; } @@ -245,17 +245,17 @@ ls(char *name) sz = getdents(fd, buf, 512); for (de = (void *) buf; de < (struct dirent *) (buf + sz); - de = (void *) de + de->namelen + sizeof(struct dirent)) { - if (de->name[0] == '.' && !allFlag) + de = (void *) de + de->d_namelen + sizeof(struct dirent)) { + if (de->d_name[0] == '.' && !allFlag) continue; curr = malloc(sizeof(Result)); curr->next = NULL; curr->prev = prev; - curr->ino = de->ino; - curr->type = de->type; - curr->namelen = de->namelen; - memcpy(curr->name, de->name, de->namelen); - curr->name[de->namelen] = '\0'; + curr->ino = de->d_ino; + curr->type = de->d_type; + curr->namelen = de->d_namelen; + memcpy(curr->name, de->d_name, de->d_namelen); + curr->name[de->d_namelen] = '\0'; stat(curr->name, &curr->stat); if (prev) prev->next = curr; diff --git a/sh/main.c b/sh/main.c index d1319ad..f4c93d2 100644 --- a/sh/main.c +++ b/sh/main.c @@ -14,7 +14,7 @@ #define PS1 "\033[1;31m%s\033[0m@\033[1m%s\033[0m:\033[1;32m%s\033[0m$> " -int argparser(char *str, char **res); +int argparser(char sep, char *str, char **res); /* Get the nice current working directory */ static void @@ -35,7 +35,6 @@ main(int argc, char *argv[]) { int fd, sz, i; char *buf; - struct stat statbuf; struct dirent *de; /* Get username */ @@ -44,8 +43,8 @@ main(int argc, char *argv[]) username = malloc(33); homedir = malloc(PATH_MAX); Passwd *pwd = getpwuid(uid); - strcpy(username, pwd->username); - strcpy(homedir, pwd->homedir); + strcpy(username, pwd->pw_name); + strcpy(homedir, pwd->pw_dir); /* Get hostname */ hostname = malloc(HOST_NAME_MAX + 1); @@ -72,7 +71,7 @@ main(int argc, char *argv[]) if (sz < 1) continue; - count = argparser(line, v); + count = argparser(' ', line, v); /* Change directory (built-in) */ if (!strcmp(v[0], "cd")) { diff --git a/sh/parser.c b/sh/parser.c index 6c0af04..d3111ca 100644 --- a/sh/parser.c +++ b/sh/parser.c @@ -2,17 +2,17 @@ /* Split a string into separate strings */ int -argparser(char *str, char **res) +argparser(char sep, char *str, char **res) { int count = 0; char *finder; memset(res, 0, 1024); finder = str; - while (*finder == ' ') finder++; + while (*finder == sep) finder++; res[count++] = finder; while (*finder) { - if (*finder == ' ') { + if (*finder == sep) { res[count++] = finder + 1; *finder = '\0'; }