Esempio n. 1
0
char *get_cgi_filename() /* and fixup environment */
{
	int buflen = 1, docrootlen;
	char *buf = NULL;
	char *docroot, *scriptname, *p;

	int rf_len;
	char *pathinfo = NULL;

	if ((p = getenv("DOCUMENT_ROOT"))) {
		docroot = p;
		buflen += docrootlen = strlen(p);
	} else {
		goto err;
	}

	if ((p = getenv("SCRIPT_NAME"))) {
		buflen += strlen(p);
		scriptname = p;
	} else {
		goto err;
	}

	buf = malloc(buflen);
	if (!buf) goto err;

	strcpy(buf, docroot);
	strcpy(buf + docrootlen, scriptname);
	pathinfo = strdup(buf);
	if (!pathinfo) {
		goto err;
	}

	while(1) {
		switch(check_file_perms(buf)) {
			case -EACCES:
				goto err;
			case 0:
				rf_len = strlen(buf);
				if (rf_len < buflen - 1) {
					setenv("PATH_INFO", pathinfo + rf_len, 1);
					setenv("SCRIPT_NAME", buf + docrootlen, 1);
				} else {
					unsetenv("PATH_INFO");
				}
				free(pathinfo);
				return buf;
			default:
				p = strrchr(buf, '/');
				if (!p) goto err;
				*p = 0;
		}
	}

err:
	free(pathinfo);
	free(buf);
	return NULL;
}
Esempio n. 2
0
char *get_cgi_filename() /* and fixup environment */
{
	int buflen = 1, docrootlen, scriptnamelen;
	char *buf = NULL;
	char *docroot, *scriptname, *p;

	int len;
	char *pathinfo = NULL;
	
        if ((p = getenv("DOCUMENT_ROOT"))) {
		docroot = p;
		buflen += docrootlen = strlen(p);
	} else {
		goto err;
	}

	if ((p = getenv("SCRIPT_NAME"))) {
		buflen += scriptnamelen = strlen(p);
		scriptname = p;
	} else {
		goto err;
	}

	buf = malloc(buflen);
	if (!buf) goto err;

	strcpy(buf, docroot);
	strcpy(buf + docrootlen, scriptname);

	while(1) {
		switch(check_file_perms(buf)) {
			case -EACCES:
				goto err;
			case 0:
                                if (fcgiwrap_cfg.fix_path_info==0) { return buf; }
                                if ( (p = getenv("SCRIPT_FILENAME"))  && (int)strlen(p) > (docrootlen + scriptnamelen) ) {
                                        pathinfo = strdup( p + docrootlen + scriptnamelen );    /* for lighttpd with broken-scriptfilename enabled */
                                } else if( (p = getenv("REQUEST_URI")) && strlen(p)>0 ) {       /* for nginx */
                                        len = strlen( getenv("QUERY_STRING") );
                                        pathinfo = strndup( p + strlen(scriptname),  strlen(p) - scriptnamelen - len - ((len==0)?0:1) );
                                } else {
                                        goto err;
                                }
				setenv("PATH_INFO", pathinfo, 1);
				free(pathinfo);
				return buf;
			default:
				p = strrchr(buf, '/');
				if (!p) goto err;
				*p = 0;
		}
	}

err:
	free(pathinfo);
	free(buf);
	return NULL;
}
Esempio n. 3
0
/**
 * Perform some sanity checks on the to-be-built package control area.
 *
 * @param dir	The directory from where to build the binary package.
 * @return	The pkginfo struct from the parsed control file.
 */
static struct pkginfo *
check_control_area(const char *ctrldir, const char *rootdir)
{
  struct pkginfo *pkg;
  int warns;

  /* Start by reading in the control file so we can check its contents. */
  pkg = check_control_file(ctrldir);
  check_file_perms(ctrldir);
  check_conffiles(ctrldir, rootdir);

  warns = warning_get_count();
  if (warns)
    warning(P_("ignoring %d warning about the control file(s)",
               "ignoring %d warnings about the control file(s)", warns),
            warns);

  return pkg;
}
Esempio n. 4
0
/**
 * Perform some sanity checks on the to-be-built package.
 *
 * @return The pkginfo struct from the parsed control file.
 */
static struct pkginfo *
check_new_pkg(const char *dir)
{
  struct pkginfo *pkg;
  struct arbitraryfield *field;
  char *controlfile;
  int warns;

  /* Start by reading in the control file so we can check its contents. */
  m_asprintf(&controlfile, "%s/%s/%s", dir, BUILDCONTROLDIR, CONTROLFILE);
  parsedb(controlfile, pdb_parse_binary, &pkg);

  if (strspn(pkg->set->name, "abcdefghijklmnopqrstuvwxyz0123456789+-.") !=
      strlen(pkg->set->name))
    ohshit(_("package name has characters that aren't lowercase alphanums or `-+.'"));
  if (pkg->priority == pri_other)
    warning(_("'%s' contains user-defined Priority value '%s'"),
            controlfile, pkg->otherpriority);
  for (field = pkg->available.arbs; field; field = field->next) {
    if (known_arbitrary_field(field))
      continue;

    warning(_("'%s' contains user-defined field '%s'"), controlfile,
            field->name);
  }

  free(controlfile);

  check_file_perms(dir);
  check_conffiles(dir);

  warns = warning_get_count();
  if (warns)
    warning(P_("ignoring %d warning about the control file(s)\n",
               "ignoring %d warnings about the control file(s)\n", warns),
            warns);

  return pkg;
}
Esempio n. 5
0
char *get_cgi_filename() /* and fixup environment */
{
	int buflen = 1, docrootlen;
	char *buf = NULL;
	char *docroot, *scriptname, *p;

	int rf_len;
	char *pathinfo = NULL;

	char *errormessage = NULL;

	if ((p = getenv("SCRIPT_FILENAME"))) {
		return strdup(p);
	}

	if ((p = getenv("DOCUMENT_ROOT"))) {
		docroot = p;
		docrootlen = strlen(p);
		buflen += docrootlen;
	} else {
		errormessage = "DOCUMENT_ROOT not set!";
		goto err;
	}

	if ((p = getenv("SCRIPT_NAME"))) {
		buflen += strlen(p);
		scriptname = p;
	} else {
		errormessage = "SCRIPT_NAME not set!";
		goto err;
	}

	buf = malloc(buflen);
	if (!buf) goto err;

	strcpy(buf, docroot);
	strcpy(buf + docrootlen, scriptname);
	pathinfo = strdup(buf);
	if (!pathinfo) {
		goto err;
	}

	while(1) {
		fprintf(stderr, "Attempting path: %s\n", buf);
		switch(check_file_perms(buf)) {
			case -EACCES:
				errormessage = "Cannot access path!";
				goto err;
			case 0:
				rf_len = strlen(buf);
				if (rf_len < buflen - 1) {
					setenv("PATH_INFO", pathinfo + rf_len, 1);
					setenv("SCRIPT_NAME", buf + docrootlen, 1);
				} else {
					unsetenv("PATH_INFO");
				}
				free(pathinfo);
				return buf;
			default:
				p = strrchr(buf, '/');
				if (!p) goto err;
				*p = 0;
		}
	}

err:
	free(pathinfo);
	free(buf);
	if(errormessage) {
	  fprintf(stderr, "%s\n", errormessage);
	}
	return NULL;
}