Exemplo n.º 1
0
/**
 * Display the header of the XML output file.
**/
void svUnitTest::svutResultFormatterXml::openOutput(void )
{
	*out << "<?xml version='1.0' encoding='UTF-8'?>" << endl;
	*out << "<!DOCTYPE UnitTest SYSTEM 'svUnitTest_html/svUnitTest.dtd'>" << endl;
	*out << "<?xml-stylesheet type='text/xsl' href='svUnitTest_html/svUnitTest.xsl'?>" << endl;
	*out << "<UnitTest>" << endl;
	printEnv();
}
Exemplo n.º 2
0
void Mysh::parseCommand(string s) {
    vector<string> commands;
    isExit = false;
    size_t foundPos = 0;
    size_t lastFoundPos = 0;
    string command = "";

    while (1) {
        foundPos = s.find_first_of("\n|!", foundPos);
        if (foundPos == string::npos)  break;

        /* 找|!后面第一个空格或换行 */
        if (s[foundPos] == '|' || s[foundPos] == '!') {
            size_t tempPos = s.find_first_of(" \n", foundPos);
            command  = s.substr(lastFoundPos, tempPos - lastFoundPos);
            commands.push_back(command);
            lastFoundPos = s.find_first_of(" ", foundPos + 1);
            foundPos = lastFoundPos;
        }
        else {
            /* foundPos 已经指到换行
             * 提取lastFoundPos 到foundPos 即可结束
             */
            command  = s.substr(lastFoundPos, foundPos - lastFoundPos);
            command += '\n';
            commands.push_back(command);
            break;
        }
    }
    isUnkCmd = 0;
    for (string::size_type i = 0; i < commands.size(); i++) {
        if(commands[i].find("exit") != string::npos) {
            isExit = true;
            return;
        }
        else if(commands[i].find("printenv") != string::npos) {
            printEnv();
            return;
        }
        else if(commands[i].find("setenv") != string::npos) {
            setEnv(commands[i]);
            return;
        }
        //cout << commands[i] << endl;
        pipeToCommand(commands[i]);
        if (isUnkCmd == 1) break;

        /* 清理掉countDown == 0 的pipe */
        pipevector.eraseInvalidPipe();
    }
    /* 将所有pipe vector中的留下pipe 的countDown减一 */
    pipevector.updateCountDown();

}
Exemplo n.º 3
0
_X_INTERNAL
int
autoLoginEnv(struct display *d, struct verify_info *verify,
    struct greet_info *greet)
{
	struct passwd	*p;
	char *shell, *home, **argv;

	Debug("Autologin %s\n", d->autoLogin);
	p = getpwnam (d->autoLogin);
	if (p == NULL)
		return 0;

	greet->name = strdup(d->autoLogin);
	if (greet->name == NULL)
		return 0;
	verify->uid = p->pw_uid;
	verify->gid = p->pw_gid;
	home = p->pw_dir;
	shell = p->pw_shell;
	argv = NULL;
	if (d->session)
		argv = parseArgs (argv, d->session);
	if (greet->string)
		argv = parseArgs (argv, greet->string);
	if (!argv)
		argv = parseArgs (argv, "xsession");
	verify->argv = argv;
	verify->userEnviron = userEnv (d, p->pw_uid == 0,
	    greet->name, home, shell);
	Debug ("user environment:\n");
	printEnv (verify->userEnviron);
	verify->systemEnviron = systemEnv (d, greet->name, home);
	Debug ("system environment:\n");
	printEnv (verify->systemEnviron);
	Debug ("end of environments\n");
	return 1;
}
Exemplo n.º 4
0
int main(int argc, char **argv, char **envp)
#endif
{
    char    *cp, *method;
    int     i, j, err;

    err = 0;
    outputArgs = outputQuery = outputEnv = outputPost = 0;
    outputBytes = outputHeaderLines = responseStatus = 0;
    outputLocation = 0;
    nonParsedHeader = 0;
    responseMsg = 0;
    hasError = 0;
    timeout = 0;
    queryBuf = 0;
    queryLen = 0;
    numQueryKeys = numPostKeys = 0;

    originalArgc = argc;
    originalArgv = argv;

#if _WIN32 && !WINCE
    _setmode(0, O_BINARY);
    _setmode(1, O_BINARY);
    _setmode(2, O_BINARY);
#endif

    if (strstr(argv[0], "nph-") != 0) {
        nonParsedHeader++;
    }
    if (getArgv(&argc, &argv, originalArgc, originalArgv) < 0) {
        error("Can't read CGI input");
    }
    for (i = 1; i < argc; i++) {
        if (argv[i][0] != '-') {
            continue;
        }
        for (cp = &argv[i][1]; *cp; cp++) {
            switch (*cp) {
            case 'a':
                outputArgs++;
                break;

            case 'b':
                if (++i >= argc) {
                    err = __LINE__;
                } else {
                    outputBytes = atoi(argv[i]);
                }
                break;

            case 'e':
                outputEnv++;
                break;

            case 'h':
                if (++i >= argc) {
                    err = __LINE__;
                } else {
                    outputHeaderLines = atoi(argv[i]);
                    nonParsedHeader++;
                }
                break;

            case 'l':
                if (++i >= argc) {
                    err = __LINE__;
                } else {
                    outputLocation = argv[i];
                    if (responseStatus == 0) {
                        responseStatus = 302;
                    }
                }
                break;

            case 'n':
                nonParsedHeader++;
                break;

            case 'p':
                outputPost++;
                break;

            case 'q':
                outputQuery++;
                break;

            case 's':
                if (++i >= argc) {
                    err = __LINE__;
                } else {
                    responseStatus = atoi(argv[i]);
                }
                break;

            case 't':
                if (++i >= argc) {
                    err = __LINE__;
                } else {
                    timeout = atoi(argv[i]);
                }
                break;

            default:
                err = __LINE__;
                break;
            }
        }
    }
    if (err) {
        fprintf(stderr, "usage: cgiProgram -aenp [-b bytes] [-h lines]\n"
            "\t[-l location] [-s status] [-t timeout]\n"
            "\tor set the HTTP_SWITCHES environment variable\n");
        fprintf(stderr, "Error at cgiProgram:%d\n", __LINE__);
        exit(255);
    }
    if ((method = getenv("REQUEST_METHOD")) != 0 && strcmp(method, "POST") == 0) {
        if (getPostData(&postBuf, &postBufLen) < 0) {
            error("Can't read CGI input");
        }
        if (strcmp(safeGetenv("CONTENT_TYPE"), "application/x-www-form-urlencoded") == 0) {
            numPostKeys = getVars(&postKeys, postBuf, postBufLen);
        }
    }

    if (hasError) {
        if (! nonParsedHeader) {
            printf("HTTP/1.0 %d %s\r\n\r\n", responseStatus, responseMsg);
            printf("<HTML><BODY><p>Error: %d -- %s</p></BODY></HTML>\r\n", responseStatus, responseMsg);
        }
        fprintf(stderr, "cgiProgram: ERROR: %s\n", responseMsg);
        exit(2);
    }

    if (nonParsedHeader) {
        if (responseStatus == 0) {
            printf("HTTP/1.0 200 OK\r\n");
        } else {
            printf("HTTP/1.0 %d %s\r\n", responseStatus, responseMsg ? responseMsg: "");
        }
        printf("Connection: close\r\n");
        printf("X-CGI-CustomHeader: Any value at all\r\n");
    }

    printf("Content-type: %s\r\n", "text/html");

    if (outputHeaderLines) {
        for (i = 0; i < outputHeaderLines; i++) {
            printf("X-CGI-%d: A loooooooooooooooooooooooong string\r\n", i);
        }
    }
    if (outputLocation) {
        printf("Location: %s\r\n", outputLocation);
    }
    if (responseStatus) {
        printf("Status: %d\r\n", responseStatus);
    }
    printf("\r\n");

    if ((outputBytes + outputArgs + outputEnv + outputQuery + outputPost + outputLocation + responseStatus) == 0) {
        outputArgs++;
        outputEnv++;
        outputQuery++;
        outputPost++;
    }

    if (outputBytes) {
        j = 0;
        for (i = 0; i < outputBytes; i++) {
            putchar('0' + j);
            j++;
            if (j > 9) {
                if (++outputBytes > 0) {
                    putchar('\r');
                }
                if (++outputBytes > 0) {
                    putchar('\n');
                }
                j = 0;
            }
        }

    } 
    printf("<HTML><TITLE>cgiProgram: Output</TITLE><BODY>\r\n");
    if (outputArgs) {
#if _WIN32
        printf("<P>CommandLine: %s</P>\r\n", GetCommandLine());
#endif
        printf("<H2>Args</H2>\r\n");
        for (i = 0; i < argc; i++) {
            printf("<P>ARG[%d]=%s</P>\r\n", i, argv[i]);
        }
    }
    printEnv(envp);
    if (outputQuery) {
        printQuery();
    }
    if (outputPost) {
        printPost(postBuf, postBufLen);
    }
    printf("</BODY></HTML>\r\n");

#if VXWORKS
    /*
        VxWorks pipes need an explicit eof string
        Must not call exit(0) in Vxworks as that will exit the task before the CGI handler can cleanup. Must use return 0.
     */
    write(1, MPR_CMD_VXWORKS_EOF, MPR_CMD_VXWORKS_EOF_LEN);
    write(2, MPR_CMD_VXWORKS_EOF, MPR_CMD_VXWORKS_EOF_LEN);
#endif
    fflush(stderr);
    fflush(stdout);
    return 0;
}
Exemplo n.º 5
0
Arquivo: bCast.c Projeto: 8l/insieme
int main (int argc, char *argv[])
{
    int err;
    double time, time_limit, time_maxMsg;

    int iter, iter_limit;
    size_t size, messStart, messStop, mem_limit;
    int testFlags, ndims, partsize;
    int k;

    char  hostname[256];
    char* hostnames;

    int root = 0;

    struct argList args;
    /* process the command-line arguments, printing usage info on error */
    if (!processArgs(argc, argv, &args)) { usage(); }
    iter       = args.iters;
    messStart  = args.messStart;
    messStop   = args.messStop;
    mem_limit  = args.memLimit;
    time_limit = args.timeLimit;
    testFlags  = args.testFlags;
    check_buffers = args.checkBuffers;
    ndims      = args.ndims;
    partsize   = args.partSize; 

    /* initialize MPI */
    err = MPI_Init(&argc, &argv);
    if (err) { printf("Error in MPI_Init\n"); exit(1); }

    /* determine who we are in the MPI world */
    MPI_Comm_rank(MPI_COMM_WORLD, &rank_local);
    MPI_Comm_size(MPI_COMM_WORLD, &rank_count);

#ifdef PRINT_ENV
   /* Print environment as part of Sequoia SOW MPI requirements */
   extern void printEnv(void);
   if (rank_local == 0) { printEnv(); }
#endif 

    /* mark start of mpiBench output */
    if (rank_local == 0) { printf("START mpiBench_Bcast v%s\n", VERS); }

    /* collect hostnames of all the processes and print rank layout */
    gethostname(hostname, sizeof(hostname));
    hostnames = (char*) _ALLOC_MAIN_(sizeof(hostname)*rank_count, "Hostname array");
    MPI_Gather(hostname, sizeof(hostname), MPI_CHAR, hostnames, sizeof(hostname), MPI_CHAR, 0, MPI_COMM_WORLD);
    if (rank_local == 0) {
        for(k=0; k<rank_count; k++) {
            printf("%d : %s\n", k, &hostnames[k*sizeof(hostname)]);
        }
    }

    /* allocate message buffers and initailize timing functions */
    while(messStop*((size_t)rank_count)*2 > mem_limit && messStop > 0) messStop /= 2;
    buffer_size = messStop * rank_count;
    sbuffer   = (char*) _ALLOC_MAIN_(messStop    * rank_count, "Send Buffer");
    rbuffer   = (char*) _ALLOC_MAIN_(messStop    * rank_count, "Receive Buffer");
    sendcounts = (int*) _ALLOC_MAIN_(sizeof(int) * rank_count, "Send Counts");
    sdispls    = (int*) _ALLOC_MAIN_(sizeof(int) * rank_count, "Send Displacements");
    recvcounts = (int*) _ALLOC_MAIN_(sizeof(int) * rank_count, "Recv Counts");
    rdispls    = (int*) _ALLOC_MAIN_(sizeof(int) * rank_count, "Recv Displacements");

    /*time_maxMsg = 2*time_limit; */
    time_maxMsg = 0.0;

    /* if partsize was specified, calculate the number of partions we need */
    int partitions = 0;
    if (partsize > 0) {
        /* keep dividing comm in half until we get to partsize */
        int currentsize = rank_count;
        while (currentsize >= partsize) {
            partitions++;
            currentsize >>= 1;
        }
    }
Exemplo n.º 6
0
_X_INTERNAL
int
Verify (struct display *d, struct greet_info *greet, struct verify_info *verify)
{
	struct passwd	*p;
	login_cap_t	*lc;
	auth_session_t	*as;
	char		*style, *shell, *home, *s, **argv;
	char		path[MAXPATHLEN];
	int		authok;
	size_t		passwd_len;

	/* User may have specified an authentication style. */
	if ((style = strchr(greet->name, ':')) != NULL)
		*style++ = '\0';

	Debug ("Verify %s, style %s ...\n", greet->name,
	    style ? style : "default");

	p = getpwnam (greet->name);
	if (!p || strlen (greet->name) == 0) {
		Debug("getpwnam() failed.\n");
		explicit_bzero(greet->password, strlen(greet->password));
		return 0;
	}

	if ((lc = login_getclass(p->pw_class)) == NULL) {
		Debug("login_getclass() failed.\n");
		explicit_bzero(greet->password, strlen(greet->password));
		return 0;
	}
	if ((style = login_getstyle(lc, style, "xdm")) == NULL) {
		Debug("login_getstyle() failed.\n");
		explicit_bzero(greet->password, strlen(greet->password));
		return 0;
	}
	if ((as = auth_open()) == NULL) {
		Debug("auth_open() failed.\n");
		login_close(lc);
		explicit_bzero(greet->password, strlen(greet->password));
		return 0;
	}
	if (auth_setoption(as, "login", "yes") == -1) {
		Debug("auth_setoption() failed.\n");
		login_close(lc);
		explicit_bzero(greet->password, strlen(greet->password));
		return 0;
	}
	passwd_len = strlen(greet->password);
	/* Set up state for no challenge, just check a response. */
	auth_setstate(as, 0);
	auth_setdata(as, "", 1);
	auth_setdata(as, greet->password, passwd_len + 1);
	/* wipe password now, otherwise it'll be copied fork() in auth_call */
	explicit_bzero(greet->password, passwd_len);
	/* Build path of the auth script and call it */
	snprintf(path, sizeof(path), _PATH_AUTHPROG "%s", style);
	auth_call(as, path, style, "-s", "response", greet->name,
		  lc->lc_class, (void *)NULL);
	authok = auth_getstate(as);

	if ((authok & AUTH_ALLOW) == 0) {
		Debug("password verify failed\n");
		auth_close(as);
		login_close(lc);
		return 0;
	}
	/* Run the approval script */
	if (!auth_approval(as, lc, greet->name, "auth-xdm")) {
		Debug("login not approved\n");
		auth_close(as);
		login_close(lc);
		return 0;
	}
	auth_close(as);
	login_close(lc);
	/* Check empty passwords against allowNullPasswd */
	if (!greet->allow_null_passwd && passwd_len == 0) {
		Debug("empty password not allowed\n");
		return 0;
	}
	/* Only accept root logins if allowRootLogin resource is set */
	if (p->pw_uid == 0 && !greet->allow_root_login) {
		Debug("root logins not allowed\n");
		return 0;
	}

	/*
	 * Shell must be in /etc/shells
	 */
	for (;;) {
		s = getusershell();
		if (s == NULL) {
			/* did not found the shell in /etc/shells
			   -> failure */
			Debug("shell not in /etc/shells\n");
			endusershell();
			return 0;
		}
		if (strcmp(s, p->pw_shell) == 0) {
			/* found the shell in /etc/shells */
			endusershell();
			break;
		}
	}

	Debug ("verify succeeded\n");
	verify->uid = p->pw_uid;
	verify->gid = p->pw_gid;
	home = p->pw_dir;
	shell = p->pw_shell;
	argv = NULL;
	if (d->session)
		argv = parseArgs (argv, d->session);
	if (greet->string)
		argv = parseArgs (argv, greet->string);
	if (!argv)
		argv = parseArgs (argv, "xsession");
	verify->argv = argv;
	verify->userEnviron = userEnv (d, p->pw_uid == 0,
				       greet->name, home, shell);
	Debug ("user environment:\n");
	printEnv (verify->userEnviron);
	verify->systemEnviron = systemEnv (d, greet->name, home);
	Debug ("system environment:\n");
	printEnv (verify->systemEnviron);
	Debug ("end of environments\n");
	return 1;
}
Exemplo n.º 7
0
int main(int argc, char * argv[], char **envp)
{
    //The following two functions catch and process the interrupt and stop signals
    //AKA signals sent by the Ctrl-C and Ctrl-Z commands
    if (signal(SIGINT,signal_catcher)==SIG_ERR)
    {
        perror("Sigset cannot set SIGINT");
        exit(SIGINT);
    }
    if (signal(SIGTSTP, signal_catcher)==SIG_ERR)
    {
        perror("Sigset can not set SIGTSTP");
        exit(SIGTSTP);
    }
    
    //Declaring and initializing variables to be used later
    initHistory();
    initAlias();
    int this_input = 0;
    
    char * input = (char *) malloc(sizeof(char)*64);
    strcpy (input, "noexit");
    char *shellname = (char *) malloc(sizeof(char)*32);
    strcpy (shellname, "myshell");
    
    setShellName(shellname);
    
    printf ("[%s]%% ", shellname);
    input = getLine(input, 100);
    
    //Making sure the program does not crash if the input simply the return key
    while (strcmp(input,"\0") == 0)
    {
        printf ("[%s]%% ", shellname);
        input = getLine(input, 100);
    }
    
    setHistory(input);
    breakLine (input);
    this_input = whichInput();
    
    char ** argrv = getargrv();
    int argrc = getargrc();
    
    int loop = 1;
    
    while (loop != 0)
    {
        //Loop and process commands until the exist command is entered
        if(this_input==4) {
            if(strcmp(argrv[argrc-1], "&")==0)
            {
                //printf("Before forking PID:%d\n", getpid());
                int pid = fork();
                if(pid==0)
                {
                    //sleep(2); //putting a delay in to emphasize background process
                    //printf("\nchild PID: %d\n", getpid());
                    decrargrc();
                    list();
                    //printf("\nIn the child process - ended.\n\n");
                    return 0;
                } else
                {
                    //printf("PPID:%d\n", getpid());
                    //printf("In the parent process.\n");
                    printf("%s process running in background", argrv[0]);
                }
            } else
                list();
            
        } else if(this_input==3) {
            if(strcmp(argrv[argrc-1], "&")==0)
            {
                int pid = fork();
                if(pid==0)
                {
                    decrargrc();
                    pwd();
                    return 0;
                } else
                    printf("%s process running in background", argrv[0]);
            } else
                pwd();
        } else if(this_input==6) {
            if(strcmp(argrv[argrc-1], "&")==0)
            {
                int pid = fork();
                if(pid==0)
                {
                    decrargrc();
                    prompt();
                    shellname = getShellName();
                    return 0;
                } else
                    printf("%s process running in background", argrv[0]);
            } else
            {
                prompt();
                shellname = getShellName();
            }
        } else if(this_input==2) {
            if(strcmp(argrv[argrc-1], "&")==0)
            {
                int pid = fork();
                if(pid==0)
                {
                    decrargrc();
                    dirChange();
                    return 0;
                } else
                    printf("%s process running in background", argrv[0]);
            } else
                dirChange();
        } else if(this_input==5) {
            if(strcmp(argrv[argrc-1], "&")==0)
            {
                int pid = fork();
                if(pid==0)
                {
                    decrargrc();
                    mypid();
                    return 0;
                } else
                    printf("%s process running in background", argrv[0]);
            } else
                mypid();
        } else if(this_input==1) {
            if (getargrc() == 1)
            {
                loop = 0;
                free (input);
                free (shellname);
                
                input = NULL;
                shellname = NULL;
                
                freeDynamicMem();
                return 0;
            } else {
                printf("%s: Arguments not valid.", argrv[0]);
            }
        } else if(this_input==7) {
            if(strcmp(argrv[argrc-1], "&")==0)
            {
                int pid = fork();
                if(pid==0)
                {
                    decrargrc();
                    printHistory();
                    return 0;
                } else
                    printf("%s process running in background", argrv[0]);
            } else
                printHistory();
        } else if(this_input==8) {
            if(strcmp(argrv[argrc-1], "&")==0)
            {
                int pid = fork();
                if(pid==0)
                {
                    printf("\n***I've put a 3 second delay in to emphasize this background process\n");
                    sleep(3); //putting a delay in to emphasize background proces
                    decrargrc();
                    printEnv(envp);
                    return 0;
                } else
                    printf("%s process running in background", argrv[0]);
            } else
                printEnv(envp);
        }else if(this_input==9) {
            if(strcmp(argrv[argrc-1], "&")==0)
            {
                int pid = fork();
                if(pid==0)
                {
                    decrargrc();
                    alias();
                    return 0;
                } else
                    printf("%s process running in background", argrv[0]);
            } else
                alias();
        }else if(this_input==10) {
            if(strcmp(argrv[argrc-1], "&")==0)
            {
                int pid = fork();
                if(pid==0)
                {
                    decrargrc();
                    murder();
                    return 0;
                } else
                    printf("%s process running in background", argrv[0]);
            } else
                murder();
        }else {
            nocmd(input);
        }
        printf ("\n[%s]%% ", shellname);
        input = getLine(input, 100);
        while (strcmp(input,"\0") == 0)
        {
            printf ("[%s]%% ", shellname);
            input = getLine(input, 100);
        }
        setHistory(input);
        breakLine (input);
        this_input = whichInput();
        argrv = getargrv();
        argrc = getargrc();
    }
    return 0;
}
Exemplo n.º 8
0
int executeBuiltinCommand(char* cmd, int argc, char** argv) {
  int status = SUCCESS;
  if (strcmp(cmd, "cd") == 0) {
    char* dest = (char*)malloc(MAX_LENGTH);
    if (argc == 2) {
      dest = argv[1];
      fixPath(dest);
    } else if (argc > 2) {
      const char* oldColor = setTermColor(stderr, KRED);
      fprintf(stderr, "cd: too many arguments\n");
      setTermColor(stderr, oldColor);
      status = ERROR;
    } else {
      sprintf(dest, "%s", getenv("HOME"));
    }
    int val = chdir(dest);
  } else if (strcmp(cmd, "alias") == 0) {
    if (argc == 3) {
      char* name = argv[1];
      char* word = argv[2];
      mapAlias(name, word);
    } else if (argc == 1) {
      printAliasTable();
    } else {
      const char* oldColor = setTermColor(stderr, KRED);
      fprintf(stderr, "alias: need 3 arguments, got %d\n", argc);
      setTermColor(stderr, oldColor);
      status = ERROR;
    }
  } else if (strcmp(cmd, "unalias") == 0) {
    if (argc == 2) {
      char* name = argv[1];
      unmapAlias(name);
    } else {
      const char* oldColor = setTermColor(stderr, KRED);
      fprintf(stderr, "unalias: need 2 arguments, got %d\n", argc);
      setTermColor(stderr, oldColor);
      status = ERROR;
    }
  } else if (strcmp(cmd, "printenv") == 0) {
    if (argc < 2) {
      printEnv();
    } else {
      const char* oldColor = setTermColor(stderr, KRED);
      fprintf(stderr, "printenv: too many arguments");
      setTermColor(stderr, oldColor);
      status = ERROR;
    }
  } else if (strcmp(cmd, "setenv") == 0) {
    if (argc == 3) {
      char* variable = argv[1];
      char* word = argv[2];
      setEnv(variable, word);
    } else {
      const char* oldColor = setTermColor(stderr, KRED);
      fprintf(stderr, "setenv: need 3 arguments, got %d\n", argc);
      setTermColor(stderr, oldColor);
      status = ERROR;
    }
  } else if (strcmp(cmd, "unsetenv") == 0) {
    if (argc == 2) {
      char* variable = argv[1];
      unsetEnv(variable);
    } else {
      const char* oldColor = setTermColor(stderr, KRED);
      fprintf(stderr, "unsetenv: need 2 arguments, got %d\n", argc);
      setTermColor(stderr, oldColor);
      status = ERROR;
    }
  } else if (strcmp(cmd, "bye") == 0) {
    exit(EXIT_SUCCESS);
  } else {
    status = ERROR;
  }
  return status;
}
Exemplo n.º 9
0
void CupsGetOpt::dumpEnv() const {
    // Env. variable debug output
    printEnv("CHARSET");
    printEnv("CLASS");
    printEnv("CONTENT_TYPE");
    printEnv("CUPS_CACHEDIR");
    printEnv("CUPS_DATADIR");
    printEnv("CUPS_FILETYPE");
    printEnv("CUPS_SERVERROOT");
    printEnv("DEVICE_URI");
    printEnv("FINAL_CONTENT_TYPE");
    printEnv("LANG");
    printEnv("PPD");
    printEnv("PRINTER");
    printEnv("RIP_CACHE");
    // FIXME: Use the TMPDIR to set LaserConfig::tempdir
    printEnv("TMPDIR");
    printEnv("PATH");
}
Exemplo n.º 10
0
Arquivo: com.c Projeto: 8l/insieme
int
main ( int argc, char *argv[] )
{
  int *messList = NULL;
  int testIdx, doTestLoop;
  int i;

  executableName = "com";

  MPI_Init ( &argc, &argv );
  MPI_Get_processor_name ( hostName, &i );

  /* Set global wsize and rank values */
  MPI_Comm_size ( MPI_COMM_WORLD, &wsize );
  MPI_Comm_rank ( MPI_COMM_WORLD, &rank );

  if ( !initAllTestTypeParams ( &testParams ) )
  {
    MPI_Finalize (  );
    exit ( 1 );
  }

  argStruct.testList = "Bidirectional, BidirAsync";

  if ( !processArgs ( argc, argv ) )
  {
    if ( rank == 0 )
      printUse (  );

    MPI_Finalize (  );
    exit ( 1 );
  }

  /* If using a source directory of process rank target files,
   * get the next appropriate file.
   */
  if ( targetDirectory != NULL && getNextTargetFile (  ) == 0 )
  {
    prestaAbort ( "Failed to open target file in target directory %s\n",
                  targetDirectory );
  }

  doTestLoop = 1;
  while ( doTestLoop )
  {
    if ( !setupTestListParams (  ) || !initAllTestTypeParams ( &testParams ) )
    {
      if ( rank == 0 )
        printUse (  );

      MPI_Finalize (  );
      exit ( 1 );
    }

#ifdef PRINT_ENV
    if ( rank == 0 )
      printEnv();
#endif

    printReportHeader (  );

    for ( testIdx = 0; testIdx < TYPETOT; testIdx++ )
    {
      if ( argStruct.testList == NULL
           || ( argStruct.testList != NULL
                && strstr ( argStruct.testList,
                            testParams[testIdx].name ) != NULL ) )
      {
        prestaRankDebug ( 0, "running test index %d\n", testIdx );
        runTest ( &testParams[testIdx] );
      }
    }

    if ( presta_check_data == 1 )
    {
      MPI_Reduce ( &presta_data_err_total, &presta_global_data_err_total,
                   1, MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD );
    }

    if ( targetDirectory == NULL || getNextTargetFile (  ) == 0 )
    {
      doTestLoop = 0;
    }
  }

  printSeparator (  );

  freeBuffers ( &testParams );
  free ( messList );

  MPI_Finalize (  );

  exit ( 0 );
}
Exemplo n.º 11
0
int parse (FILE *in, FILE *out) {
	char *input = malloc(MAXLEN);
	char *test = fgets(input, MAXLEN, in);
	
	size_t n = atoi(test); //number of events
	size_t step = 1; //current step;
	
	//create Events stacks
	AStack *Events = initEvents(n);
	if (!Events) {
		return 1;
	}
	
	//create process queue
	AQueue aQ = initQ(sizeof(TProcess));
	
	int check = 1; //used for checking function output
	
	test = fgets(input, MAXLEN, in);
	while (test != NULL && test[0] != '\n') {
		//tokenize input 
		char *cmd[3] = {0};
		int i = 0;
		char *aux = strtok(test, " \n");
		while (aux != NULL) {
			cmd[i] = aux;
			++i;
			aux = strtok(NULL, " \n");
		}
		
		if (cmd[0] != NULL) {
			//call function accordingly
			if (!strcmp(cmd[0], "start")) {
				check = start(atoi(cmd[1]), atoi(cmd[2]), step, aQ);
			} else if (!strcmp(cmd[0], "wait")) {
				check = wait(atoi(cmd[1]), atoi(cmd[2]), &aQ, Events);
			} else if (!strcmp(cmd[0], "event")) {
				check = event(atoi(cmd[1]), aQ, Events);
			} else if (!strcmp(cmd[0], "end")) {
				check = end(atoi(cmd[1]), &aQ);
			}
		}
		
		//if some of the functions encountered problems exit loop (and program)
		//most probably will not happen
		if (check != 1) {
			for (size_t i = 0; i < n; i++) {
				destroyS(&Events[i]);
			}
			free(Events);
			destroyQ(&aQ);
			free(input);
			return check;
		}
		
		printEnv(step, n, aQ, Events, out);
		test = fgets(input, MAXLEN, in);
		++step;
	}	
	
	//free what needs to be freed
	for (size_t i = 0; i < n; i++) {
		destroyS(&Events[i]);
	}
	free(Events);
	destroyQ(&aQ);
	free(input);
	return 1;
}
Exemplo n.º 12
0
Arquivo: command.c Projeto: jsvana/jsh
int process(int argc, char **argv, environment env) {
    char *command = argv[0];

    if (argc == 0) {
        return lastStatus;
    } else if (strlen(command) > 2 && command[0] == '.' && command[1] == '/') {
        char *path;
        asprintf(&path, "%s/%s", cwd, command);
        if (path == NULL) {
            TERM_ERR("Unable to allocate asprintf memory\n");
        }

        cpid = fork();
        if (cpid < 0) {
            TERM_ERR("Unable to fork\n");
        } else if (cpid == 0) {
            execve(path, argv, env.variables);
        } else {
            int status;
            wait(&status);
            if (WIFEXITED(status)) {
                return WEXITSTATUS(status) == 0;
            } else {
                return FALSE;
            }
        }
        free(path);
        cpid = -1;
    } else if (strcmp(command, "exit") == 0) {
        fprintf(stdout, "Exiting...\n");
        termRunning = FALSE;

        return TRUE;
    } else if (strcmp(command, "cd") == 0) {
        if (argc == 1) {
            free(cwd);

            char *home = getValue(getEnv(env, "HOME"));

            if (chdir(home) != -1) {
                cwd = (char *)malloc(sizeof(char) * (strlen(home) + 1));
                memset(cwd, 0, sizeof(char) * (strlen(home) + 1));
                strcpy(cwd, home);

                return TRUE;
            } else {
                return FALSE;
            }
        } else {
            free(cwd);
            if (chdir(argv[1]) != -1) {
                cwd = getcwd(NULL, 0);

                return TRUE;
            } else {
                return FALSE;
            }
        }
    } else if (strcmp(command, "pwd") == 0) {
        char *cwd = getcwd(NULL, 0);
        fprintf(stdout, "%s\n", cwd);
        free(cwd);

        return TRUE;
    } else if (strcmp(command, "env") == 0) {
        printEnv(env);

        return TRUE;
    } else {
        char *path = find(getValue(getEnv(env, "PATH")), command);

        if (path != NULL) {
            cpid = fork();
            if (cpid < 0) {
                TERM_ERR("Unable to fork\n");
            } else if (cpid == 0) {
                execve(path, argv, env.variables);
            } else {
                int status;
                wait(&status);
                if (WIFEXITED(status)) {
                    return WEXITSTATUS(status) == 0;
                } else {
                    return FALSE;
                }
            }
            free(path);
            cpid = -1;

            return TRUE;
        }
    }

    fprintf(stderr, "jsh: Unknown command \"%s\"\n", command);

    return FALSE;
}
Exemplo n.º 13
0
/**
 * Main entry point for the program.
 *
 * @param argc The number of command line options passed to the program.
 * @param argv An array of strings where each string represents a command line
 * argument.
 * @return An integer where 0 represents successful termination, any other
 * value represents an error code.
 */
int main(int argc, char *argv[])
{
  // Make sure status messages are not buffered
  setbuf(stderr, NULL);

  if (argc < 6 || argc > 7) {
    fprintf(stderr, "ERROR: Usage: %s job-id user title copies options [file]\n", argv[0]);
    return 1;
  }

  fprintf(stderr, "DEBUG: Start debug output - passthroughfilter\n");

  // Arguments debug output:
  fprintf(stderr, "DEBUG: ");
  for (int i=0;i<argc;i++) {
    // Don't print the option arg - these are parsed and output later
    if (i != 5) {
      fprintf(stderr, "%s ", argv[i]);
    }
  }
  fprintf(stderr, "\n");

  // Env. variable debug output
  printEnv("CHARSET");
  printEnv("CLASS");
  printEnv("CONTENT_TYPE");
  printEnv("CUPS_CACHEDIR");
  printEnv("CUPS_DATADIR");
  printEnv("CUPS_FILETYPE");
  printEnv("CUPS_SERVERROOT");
  printEnv("DEVICE_URI");
  printEnv("FINAL_CONTENT_TYPE");
  printEnv("LANG");
  printEnv("PATH");
  printEnv("PPD");
  printEnv("PRINTER");
  printEnv("RIP_CACHE");
  printEnv("SOFTWARE");
  printEnv("TZ");
  printEnv("USER");

  cups_option_t	*options = NULL;
  int num_options = cupsParseOptions(argv[5], 0, &options);
  for (int i=0;i<num_options;i++) {
    fprintf(stderr, "DEBUG: %s: %s\n", options[i].name, options[i].value);
  }

  // FIXME: Register a signal handler to support cancelling of jobs

  cups_file_t *fp;
  if (argc == 6) {
    fp = cupsFileStdin();
  } else {
    // Try to open the print file...
    if ((fp = cupsFileOpen(argv[6], "r")) == NULL) {
      perror("ERROR: unable to open print file - ");
      return 1;
    }
  }

  char buffer[8192];
  int bytes;
  while ((bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0) {
    fwrite(buffer, 1, bytes, stdout);
  }

  fprintf(stderr, "DEBUG: End debug output - passthroughfilter\n");
  return 0;
}
Exemplo n.º 14
0
int
Verify (struct display *d, struct greet_info *greet, struct verify_info *verify)
{
	struct passwd	*p;
	login_cap_t	*lc;
	auth_session_t	*as;
	char		*style, *shell, *home, *s, **argv;
	char		path[MAXPATHLEN];
	int		authok;

	/* User may have specified an authentication style. */
	if ((style = strchr(greet->name, ':')) != NULL)
		*style++ = '\0';

	Debug ("Verify %s, style %s ...\n", greet->name,
	    style ? style : "default");

	p = getpwnam (greet->name);
	endpwent();

	if (!p || strlen (greet->name) == 0) {
		Debug("getpwnam() failed.\n");
		bzero(greet->password, strlen(greet->password));
		return 0;
	}

	if ((lc = login_getclass(p->pw_class)) == NULL) {
		Debug("login_getclass() failed.\n");
		bzero(greet->password, strlen(greet->password));
		return 0;
	}
	if ((style = login_getstyle(lc, style, "xdm")) == NULL) {
		Debug("login_getstyle() failed.\n");
		bzero(greet->password, strlen(greet->password));
		return 0;
	}
	if ((as = auth_open()) == NULL) {
		Debug("auth_open() failed.\n");
		login_close(lc);
		bzero(greet->password, strlen(greet->password));
		return 0;
	}
	if (auth_setoption(as, "login", "yes") == -1) {
		Debug("auth_setoption() failed.\n");
		login_close(lc);
		bzero(greet->password, strlen(greet->password));
		return 0;
	}

	/* Set up state for no challenge, just check a response. */
	auth_setstate(as, 0);
	auth_setdata(as, "", 1);
	auth_setdata(as, greet->password, strlen(greet->password) + 1);

	/* Build path of the auth script and call it */
	snprintf(path, sizeof(path), _PATH_AUTHPROG "%s", style);
	auth_call(as, path, style, "-s", "response", greet->name, 
		  lc->lc_class, (void *)NULL);
	authok = auth_getstate(as);

	if ((authok & AUTH_ALLOW) == 0) {
		Debug("password verify failed\n");
		bzero(greet->password, strlen(greet->password));
		auth_close(as);
		login_close(lc);
		return 0;
	}
	/* Run the approval script */
	if (!auth_approval(as, lc, greet->name, "auth-xdm")) {
		Debug("login not approved\n");
		bzero(greet->password, strlen(greet->password));
		auth_close(as);
		login_close(lc);
		return 0;
	}
	auth_close(as);
	login_close(lc);
	/* Check empty passwords against allowNullPasswd */
	if (!greet->allow_null_passwd && strlen(greet->password) == 0) {
		Debug("empty password not allowed\n");
		return 0;
	}
	/* Only accept root logins if allowRootLogin resource is set */
	if (p->pw_uid == 0 && !greet->allow_root_login) {
		Debug("root logins not allowed\n");
		bzero(greet->password, strlen(greet->password));
		return 0;
	}

	/*
	 * Shell must be in /etc/shells 
	 */
	for (;;) {
		s = getusershell();
		if (s == NULL) {
			/* did not found the shell in /etc/shells 
			   -> failure */
			Debug("shell not in /etc/shells\n");
			bzero(greet->password, strlen(greet->password));
			endusershell();
			return 0;
		}
		if (strcmp(s, p->pw_shell) == 0) {
			/* found the shell in /etc/shells */
			endusershell();
			break;
		}
	} 
#else /* !USE_BSDAUTH */
int
Verify (struct display *d, struct greet_info *greet, struct verify_info *verify)
{
	struct passwd	*p;
#ifdef USE_PAM
	pam_handle_t **pamhp = thepamhp();
#else
#ifdef USESHADOW
	struct spwd	*sp;
#endif
	char		*user_pass = NULL;
#endif
#ifdef __OpenBSD__
	char            *s;
	struct timeval  tp;
#endif
	char		*shell, *home;
	char		**argv;

	Debug ("Verify %s ...\n", greet->name);

#if defined(sun) && defined(SVR4)
	/* Solaris: If CONSOLE is set to /dev/console in /etc/default/login, 
	   then root can only login on system console */

# define SOLARIS_LOGIN_DEFAULTS "/etc/default/login"

	if (strcmp(greet->name, "root") == 0) {
	    char *console = NULL, *tmp = NULL;
	    FILE *fs;

	    if ((fs= fopen(SOLARIS_LOGIN_DEFAULTS, "r")) != NULL)
	    {   
		char str[120];
		while (!feof(fs))
		{
		    fgets(str, 120, fs);
		    if(str[0] == '#' || strlen(str) < 8)
			continue;
		    if((tmp = strstr(str, "CONSOLE=")) != NULL)
			console = strdup((tmp+8));
		}
		fclose(fs);
                if ( console != NULL && 
		  (strncmp(console, "/dev/console", 12) == 0) && 
		  (strncmp(d->name,":0",2) != 0) )
		{
                        Debug("Not on system console\n");
                        bzero(greet->password, strlen(greet->password));
             		XFree(console); 
	                return 0;
                }
		XFree(console);	
	    }
	    else
	    {
		Debug("Could not open %s\n", SOLARIS_LOGIN_DEFAULTS);
	    }	
	}
#endif    

#ifndef USE_PAM
	p = getpwnam (greet->name);
	endpwent();

	if (!p || strlen (greet->name) == 0) {
		Debug ("getpwnam() failed.\n");
		bzero(greet->password, strlen(greet->password));
		return 0;
	} else {
#ifdef linux
	    if (!strcmp(p->pw_passwd, "!") || !strcmp(p->pw_passwd, "*")) {
		Debug ("The account is locked, no login allowed.\n");
		bzero(greet->password, strlen(greet->password));
		return 0;
	    }
#endif
	    user_pass = p->pw_passwd;
	}
#endif
#ifdef KERBEROS
	if(strcmp(greet->name, "root") != 0){
		char name[ANAME_SZ];
		char realm[REALM_SZ];
		char *q;
		int ret;
	    
		if(krb_get_lrealm(realm, 1)){
			Debug ("Can't get Kerberos realm.\n");
		} else {

		    sprintf(krbtkfile, "%s.%s", TKT_ROOT, d->name);
		    krb_set_tkt_string(krbtkfile);
		    unlink(krbtkfile);
           
		    ret = krb_verify_user(greet->name, "", realm, 
				      greet->password, 1, "rcmd");
           
		    if(ret == KSUCCESS){
			    chown(krbtkfile, p->pw_uid, p->pw_gid);
			    Debug("kerberos verify succeeded\n");
			    if (k_hasafs()) {
				    if (k_setpag() == -1)
					    LogError ("setpag() failed for %s\n",
						      greet->name);
				    
				    if((ret = k_afsklog(NULL, NULL)) != KSUCCESS)
					    LogError("Warning %s\n", 
						     krb_get_err_text(ret));
			    }
			    goto done;
		    } else if(ret != KDC_PR_UNKNOWN && ret != SKDC_CANT){
			    /* failure */
			    Debug("kerberos verify failure %d\n", ret);
			    krbtkfile[0] = '\0';
		    }
		}
	}
#endif
#ifndef USE_PAM
#ifdef USESHADOW
	errno = 0;
	sp = getspnam(greet->name);
	if (sp == NULL) {
	    Debug ("getspnam() failed, errno=%d.  Are you root?\n", errno);
	} else {
	    user_pass = sp->sp_pwdp;
	}
#ifndef QNX4
	endspent();
#endif  /* QNX4 doesn't need endspent() to end shadow passwd ops */
#endif
#if defined(ultrix) || defined(__ultrix__)
	if (authenticate_user(p, greet->password, NULL) < 0)
#else
	if (strcmp (crypt (greet->password, user_pass), user_pass))
#endif
	{
		if(!greet->allow_null_passwd || strlen(p->pw_passwd) > 0) {
			Debug ("password verify failed\n");
			bzero(greet->password, strlen(greet->password));
			return 0;
		} /* else: null passwd okay */
	}
#ifdef KERBEROS
done:
#endif
#ifdef __OpenBSD__
	/*
	 * Only accept root logins if allowRootLogin resource is set
	 */
	if ((p->pw_uid == 0) && !greet->allow_root_login) {
		Debug("root logins not allowed\n");
		bzero(greet->password, strlen(greet->password));
		return 0;
	}
	/*
	 * Shell must be in /etc/shells 
	 */
	for (;;) {
		s = getusershell();
		if (s == NULL) {
			/* did not found the shell in /etc/shells 
			   -> failure */
			Debug("shell not in /etc/shells\n");
			bzero(greet->password, strlen(greet->password));
			endusershell();
			return 0;
		}
		if (strcmp(s, p->pw_shell) == 0) {
			/* found the shell in /etc/shells */
			endusershell();
			break;
		}
	} 
	/*
	 * Test for expired password
	 */
	if (p->pw_change || p->pw_expire)
		(void)gettimeofday(&tp, (struct timezone *)NULL);
	if (p->pw_change) {
		if (tp.tv_sec >= p->pw_change) {
			Debug("Password has expired.\n");
			bzero(greet->password, strlen(greet->password));
			return 0;
		}
	}
	if (p->pw_expire) {
		if (tp.tv_sec >= p->pw_expire) {
			Debug("account has expired.\n");
			bzero(greet->password, strlen(greet->password));
			return 0;
		} 
	}
#endif /* __OpenBSD__ */
	bzero(user_pass, strlen(user_pass)); /* in case shadow password */

#else /* USE_PAM */
#define PAM_BAIL	\
	if (pam_error != PAM_SUCCESS) goto pam_failed;

	PAM_password = greet->password;
	pam_error = pam_start("xdm", greet->name, &PAM_conversation, pamhp);
	PAM_BAIL;
	pam_error = pam_set_item(*pamhp, PAM_TTY, d->name);
	PAM_BAIL;
	pam_error = pam_set_item(*pamhp, PAM_RHOST, "");
	PAM_BAIL;
	pam_error = pam_authenticate(*pamhp, 0);
	PAM_BAIL;
	pam_error = pam_acct_mgmt(*pamhp, 0);
	/* really should do password changing, but it doesn't fit well */
	PAM_BAIL;
	pam_error = pam_setcred(*pamhp, 0);
	PAM_BAIL;
	p = getpwnam (greet->name);
	endpwent();

	if (!p || strlen (greet->name) == 0) {
		Debug ("getpwnam() failed.\n");
		bzero(greet->password, strlen(greet->password));
		return 0;
	}

	if (pam_error != PAM_SUCCESS) {
	pam_failed:
		pam_end(*pamhp, PAM_SUCCESS);
		*pamhp = NULL;
		return 0;
	}
#undef PAM_BAIL
#endif /* USE_PAM */
#endif /* USE_BSDAUTH */

	Debug ("verify succeeded\n");
	/* The password is passed to StartClient() for use by user-based
	   authorization schemes.  It is zeroed there. */
	verify->uid = p->pw_uid;
	verify->gid = p->pw_gid;
	home = p->pw_dir;
	shell = p->pw_shell;
	argv = 0;
	if (d->session)
		argv = parseArgs (argv, d->session);
	if (greet->string)
		argv = parseArgs (argv, greet->string);
	if (!argv)
		argv = parseArgs (argv, "xsession");
	verify->argv = argv;
	verify->userEnviron = userEnv (d, p->pw_uid == 0,
				       greet->name, home, shell);
	Debug ("user environment:\n");
	printEnv (verify->userEnviron);
	verify->systemEnviron = systemEnv (d, greet->name, home);
	Debug ("system environment:\n");
	printEnv (verify->systemEnviron);
	Debug ("end of environments\n");
	return 1;
}