cvs: /php3/functions php3_posix.h posix.c
| From: | Kristian K�hntopp | Date: | Sun, 12 Sep 1999 17:19:57 +0000 |
| Subject: | cvs: /php3/functions php3_posix.h posix.c | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-10828@lists.php.net to get a copy of this message | ||
kk Sun Sep 12 13:19:57 1999 EDT
Modified files:
/php3/functions php3_posix.h posix.c
Log:
The rest of the posix module. We could add further non-posix functions
here for shadow password access and similar, if someone requests this.
Index: php3/functions/php3_posix.h
diff -u php3/functions/php3_posix.h:1.3 php3/functions/php3_posix.h:1.4
--- php3/functions/php3_posix.h:1.3 Sun Sep 12 10:07:27 1999
+++ php3/functions/php3_posix.h Sun Sep 12 13:19:56 1999
@@ -28,7 +28,7 @@
*/
-/* $Id: php3_posix.h,v 1.3 1999/09/12 14:07:27 kk Exp $ */
+/* $Id: php3_posix.h,v 1.4 1999/09/12 17:19:56 kk Exp $ */
#ifndef _PHP3_POSIX_H
#define _PHP3_POSIX_H
@@ -75,6 +75,14 @@
extern void php3_posix_ctermid(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_posix_ttyname(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_posix_isatty(INTERNAL_FUNCTION_PARAMETERS);
+
+extern void php3_posix_getcwd(INTERNAL_FUNCTION_PARAMETERS);
+
+extern void php3_posix_mkfifo(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_getgrnam(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_getgrgid(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_getpwnam(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_getpwuid(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_posix_getrlimit(INTERNAL_FUNCTION_PARAMETERS);
Index: php3/functions/posix.c
diff -u php3/functions/posix.c:1.10 php3/functions/posix.c:1.11
--- php3/functions/posix.c:1.10 Sun Sep 12 11:29:44 1999
+++ php3/functions/posix.c Sun Sep 12 13:19:56 1999
@@ -27,7 +27,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: posix.c,v 1.10 1999/09/12 15:29:44 eschmid Exp $ */
+/* $Id: posix.c,v 1.11 1999/09/12 17:19:56 kk Exp $ */
#include "php.h"
@@ -47,9 +47,12 @@
#include <sys/resource.h>
#include <sys/utsname.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <signal.h>
#include <sys/times.h>
#include <errno.h>
+#include <grp.h>
+#include <pwd.h>
#include "php3_list.h"
#define SAFE_STRING(s) ((s)?(s):"")
@@ -90,7 +93,19 @@
{"posix_ctermid", php3_posix_ctermid, NULL},
{"posix_ttyname", php3_posix_ttyname, NULL},
{"posix_isatty", php3_posix_isatty, NULL},
-
+
+ /* POSIX.1, 5.2 */
+ {"posix_getcwd", php3_posix_getcwd, NULL},
+
+ /* POSIX.1, 5.4 */
+ {"posix_mkfifo", php3_posix_mkfifo, NULL},
+
+ /* POSIX.1, 9.2 */
+ {"posix_getgrnam", php3_posix_getgrnam, NULL},
+ {"posix_getgrgid", php3_posix_getgrgid, NULL},
+ {"posix_getpwnam", php3_posix_getpwnam, NULL},
+ {"posix_getpwuid", php3_posix_getpwuid, NULL},
+
{"posix_getrlimit", php3_posix_getrlimit, NULL},
{NULL, NULL, NULL}
@@ -128,7 +143,7 @@
void php3_info_posix(void)
{
- php3_printf("$Revision: 1.10 $\n");
+ php3_printf("$Revision: 1.11 $\n");
}
/* {{{ proto int posix_kill(int pid, int sig)
@@ -140,7 +155,7 @@
pval *sig;
int result;
- if (getParameters(ht, 2, &pid, &sig)==FAILURE) {
+ if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &pid, &sig)==FAILURE) {
WRONG_PARAM_COUNT;
}
@@ -233,7 +248,7 @@
pval *uid;
int result;
- if (getParameters(ht, 1, &uid)==FAILURE) {
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &uid)==FAILURE) {
WRONG_PARAM_COUNT;
}
@@ -258,7 +273,7 @@
pval *gid;
int result;
- if (getParameters(ht, 1, &gid)==FAILURE) {
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &gid)==FAILURE) {
WRONG_PARAM_COUNT;
}
@@ -347,7 +362,7 @@
pval *pgid;
int result;
- if (getParameters(ht, 2, &pid, &pgid)==FAILURE) {
+ if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &pid, &pgid)==FAILURE) {
WRONG_PARAM_COUNT;
}
@@ -375,7 +390,7 @@
pid_t pgid;
pval *pid;
- if (getParameters(ht, 1, &pid)==FAILURE) {
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &pid)==FAILURE) {
WRONG_PARAM_COUNT;
}
@@ -404,7 +419,7 @@
pid_t sid;
pval *pid;
- if (getParameters(ht, 1, &pid)==FAILURE) {
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &pid)==FAILURE) {
WRONG_PARAM_COUNT;
}
@@ -501,7 +516,7 @@
pval *fd;
char *p;
- if (getParameters(ht, 1, &fd)==FAILURE) {
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &fd)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(fd);
@@ -525,7 +540,7 @@
pval *fd;
int result;
- if (getParameters(ht, 1, &fd)==FAILURE) {
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &fd)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(fd);
@@ -540,10 +555,220 @@
/*
POSIX.1, 4.8.1 sysconf() - TODO
+ POSIX.1, 5.7.1 pathconf(), fpathconf() - TODO
- POSIX.1, 5.2.1 opendir(), readdir(), rewinddir(), closedir()
+ POSIX.1, 5.1.2 opendir(), readdir(), rewinddir(), closedir()
+ POSIX.1, 5.2.1 chdir()
already supported by PHP
*/
+
+/* {{{ proto string posix_getcwd()
+ Get working directory pathname (POSIX.1, 5.2.2) */
+void php3_posix_getcwd(INTERNAL_FUNCTION_PARAMETERS)
+{
+ char buffer[PATH_MAX];
+ char *p;
+
+ p = getcwd(buffer, PATH_MAX);
+ if (!p) {
+ php3_error(E_WARNING, "posix_getcwd() failed with '%s'",
+ strerror(errno));
+ RETURN_FALSE;
+ }
+
+ RETURN_STRING(buffer, 1);
+}
+/* }}} */
+
+/*
+ POSIX.1, 5.3.x open(), creat(), umask()
+ POSIX.1, 5.4.1 link()
+ already supported by PHP.
+ */
+
+/* {{{ proto string posix_mkfifo()
+ Make a FIFO Special File (POSIX.1, 5.4.2) */
+void php3_posix_mkfifo(INTERNAL_FUNCTION_PARAMETERS)
+{
+ pval *path;
+ pval *mode;
+ int result;
+
+ if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &path, &mode) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_string(path);
+ convert_to_long(mode);
+
+ if (php3_ini.safe_mode && (!_php3_checkuid(path->value.str.val, 3))) {
+ RETURN_FALSE;
+ }
+ result = mkfifo(path->value.str.val, mode->value.lval);
+ if (result < 0) {
+ php3_error(E_WARNING, "posix_mkfifo(%s) failed with '%s'",
+ path->value.str.val,
+ strerror(errno));
+ RETURN_FALSE;
+ }
+
+ RETURN_TRUE;
+}
+
+/*
+ POSIX.1, 5.5.1 unlink()
+ POSIX.1, 5.5.2 rmdir()
+ POSIX.1, 5.5.3 rename()
+ POSIX.1, 5.6.x stat(), access(), chmod(), utime()
+ already supported by PHP (access() not supported, because it is
+ braindead and dangerous and gives outdated results).
+
+ POSIX.1, 6.x most I/O functions already supported by PHP.
+ POSIX.1, 7.x tty functions, TODO
+ POSIX.1, 8.x interactions with other C language functions
+ POSIX.1, 9.x system database access
+ */
+
+/* {{{ proto array posix_getgrnam(string groupname)
+ Group Database Access (POSIX.1, 9.2.1) */
+void php3_posix_getgrnam(INTERNAL_FUNCTION_PARAMETERS)
+{
+ pval *name;
+ char buffer[10];
+ struct group *g;
+ char **p;
+ int count;
+
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &name)==FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_string(name);
+
+ g = getgrnam(name->value.str.val);
+ if (!g) {
+ php3_error(E_WARNING, "posix_getgrnam(%s) failed with '%s'",
+ name->value.str.val,
+ strerror(errno));
+ RETURN_FALSE;
+ }
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+ add_assoc_string(return_value, "name", g->gr_name, strlen(g->gr_name));
+ add_assoc_long (return_value, "gid", g->gr_gid);
+ for (count=0, p=g->gr_mem; p[count] != NULL; count++) {
+ snprintf(buffer, 10, "%d", count);
+ add_assoc_string(return_value, buffer, p[count], strlen(p[count]));
+ }
+ add_assoc_long(return_value, "members", count);
+}
+/* }}} */
+
+
+/* {{{ proto array posix_getgrgid(long gid)
+ Group Database Access (POSIX.1, 9.2.1) */
+void php3_posix_getgrgid(INTERNAL_FUNCTION_PARAMETERS)
+{
+ pval *gid;
+ char buffer[10];
+ struct group *g;
+ char **p;
+ int count;
+
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &gid)==FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_long(gid);
+
+ g = getgrgid(gid->value.lval);
+ if (!g) {
+ php3_error(E_WARNING, "posix_getgrgid(%d) failed with '%s'",
+ gid->value.lval,
+ strerror(errno));
+ RETURN_FALSE;
+ }
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+ add_assoc_string(return_value, "name", g->gr_name, strlen(g->gr_name));
+ add_assoc_long (return_value, "gid", g->gr_gid);
+ for (count=0, p=g->gr_mem; p[count] != NULL; count++) {
+ snprintf(buffer, 10, "%d", count);
+ add_assoc_string(return_value, buffer, p[count], strlen(p[count]));
+ }
+ add_assoc_long(return_value, "members", count);
+}
+/* }}} */
+
+/* {{{ proto array posix_getpwnam(string groupname)
+ User Database Access (POSIX.1, 9.2.2) */
+void php3_posix_getpwnam(INTERNAL_FUNCTION_PARAMETERS)
+{
+ pval *name;
+ char buffer[10];
+ struct passwd *pw;
+ char **p;
+ int count;
+
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &name)==FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_string(name);
+
+ pw = getpwnam(name->value.str.val);
+ if (!pw) {
+ php3_error(E_WARNING, "posix_getpwnam(%s) failed with '%s'",
+ name->value.str.val,
+ strerror(errno));
+ RETURN_FALSE;
+ }
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+ add_assoc_string(return_value, "name", pw->pw_name, strlen(pw->pw_name));
+ add_assoc_string(return_value, "passwd", pw->pw_passwd, strlen(pw->pw_passwd));
+ add_assoc_long (return_value, "uid", pw->pw_uid);
+ add_assoc_long (return_value, "gid", pw->pw_gid);
+ add_assoc_string(return_value, "gecos", pw->pw_gecos, strlen(pw->pw_gecos));
+ add_assoc_string(return_value, "dir", pw->pw_dir, strlen(pw->pw_dir));
+ add_assoc_string(return_value, "shell", pw->pw_shell, strlen(pw->pw_shell));
+}
+/* }}} */
+
+/* {{{ proto array posix_getpwuid(long uid)
+ User Database Access (POSIX.1, 9.2.2) */
+void php3_posix_getpwuid(INTERNAL_FUNCTION_PARAMETERS)
+{
+ pval *uid;
+ char buffer[10];
+ struct passwd *pw;
+ char **p;
+ int count;
+
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &uid)==FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_long(uid);
+
+ pw = getpwuid(uid->value.lval);
+ if (!pw) {
+ php3_error(E_WARNING, "posix_getpwuid(%d) failed with '%s'",
+ uid->value.lval,
+ strerror(errno));
+ RETURN_FALSE;
+ }
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+ add_assoc_string(return_value, "name", pw->pw_name, strlen(pw->pw_name));
+ add_assoc_string(return_value, "passwd", pw->pw_passwd, strlen(pw->pw_passwd));
+ add_assoc_long (return_value, "uid", pw->pw_uid);
+ add_assoc_long (return_value, "gid", pw->pw_gid);
+ add_assoc_string(return_value, "gecos", pw->pw_gecos, strlen(pw->pw_gecos));
+ add_assoc_string(return_value, "dir", pw->pw_dir, strlen(pw->pw_dir));
+ add_assoc_string(return_value, "shell", pw->pw_shell, strlen(pw->pw_shell));
+}
+/* }}} */
+
#if HAVE_GETRLIMIT
static int posix_addlimit(int limit, char *name, pval *return_value) {