Esempio n. 1
0
ConsoleView::ConsoleView(int x,int y,int w,int h) : BufferedView(x,y,w,h) {
	// this should take into account the size of the screen
	// and stuff like that, but for now we'll just make it big...
	int width_chars = 80;
	int height_chars = 80;
	int buf_size = (width_chars * (height_chars * 2)) * sizeof(char);

	conTest = new ConsoleData(30);
	myData  = new ConsoleData(20000);

        isRunningLua = 0;
	needFullPaint = 0;
	inputRowHeight = 0;
	consoleViewDisabled = 0;
	wantsInputFocus = 1;
	scrollback_lines = 0;
	curPrompt = "> ";  // set the default prompt string
	consoleHandler = NULL; // nullify the callback..


#if 0
	hndlMgr->addHandle(linepen =  CreatePen(PS_SOLID,0,RGB(255,255,0)));
	hndlMgr->addHandle(blackpen = CreatePen(PS_SOLID,0,RGB(0,0,0)));
	hndlMgr->addHandle(blackbrush = CreateSolidBrush(RGB(0,0,0)));
	
	if (!linepen || !blackpen || !blackbrush) {
		CleanupAndExit("Couldn't CreatePen() in ConsoleView::ConsoleView()");
	}
#endif

	


	// allocate the bufferspace..
	inputMaxLen = 512;
	if ((inputString = (char *)malloc(inputMaxLen)) == NULL) {
		CleanupAndExit("Couldn't allocate input buffer!");
	}
	curInputPos = 0;
	strcpy(inputString,curPrompt);
	oldPromptLen = curInputPos = strlen(inputString);

	if ((myBuffer.start = (char *)malloc(buf_size)) == NULL)  {
		CleanupAndExit("Couldn't allocate text buffer!");
	}
	myBuffer.end = myBuffer.start + buf_size;
	myBuffer.head = myBuffer.tail = myBuffer.start;

	
	computeSizes();
	clear();
	repaint();
}
Esempio n. 2
0
void 
RespondDialogCB(
        Widget w,
        XtPointer client,
        XtPointer call_data)
{
  char buf[REQUEST_LIM_MAXLEN];
  XmAnyCallbackStruct *reason = (XmAnyCallbackStruct *)call_data;

#ifdef VG_TRACE
  vg_TRACE_EXECUTION("main:  entered RespondDialogCB ...");
#endif /* VG_TRACE */

  if (w == error_message)
  {
  ResponseMessage *r= (ResponseMessage *)buf;

  r->hdr.opcode = REQUEST_OP_MESSAGE;
  r->hdr.reserved = 0;
  r->hdr.length = sizeof(*r);

  TellRequester(buf, (size_t) r->hdr.length);
  } 
  else if (w == passwd_message)
  {
    if (reason->reason == XmCR_OK)
    {
      CleanupAndExit(w, NOTIFY_PASSWD_EXPIRED);
    } 
    else
    {
  ResponseExpassword *r= (ResponseExpassword *)buf;

  r->hdr.opcode = REQUEST_OP_EXPASSWORD;
  r->hdr.reserved = 0;
  r->hdr.length = sizeof(*r);

  TellRequester(buf, (size_t) r->hdr.length);
    }
  }
  else if (w == hostname_message)
  {
    if (reason->reason == XmCR_OK)
    {
      CleanupAndExit(w, NOTIFY_OK);
    } 
    else
    {
      CleanupAndExit(w, NOTIFY_NO_WINDOWS);
    }
  }
}
/*
 * AddPassword: Prompts the user for a password
 *              and adds the entry in the file
 *              user:crpytofpassword:md5hash(user:realm:password) 
 */
static void AddPassword(char *user, char* realm, FILE *f)
{
    char *pw, *crpw, cpw[120], salt[9], *dpw;
    int len = 0, i = 0, crpwLen = 0;
    char *checkw;

    pw = CopyString((char *) getpass("New password:"******"Password cannot be blank, sorry.\n");
        delete(checkw);
        CleanupAndExit();
    }
    delete(checkw);
    
    if (strcmp(pw, (char *) getpass("Re-type new password:"******"They don't match, sorry.\n");
		CleanupAndExit();
    }
	
    (void) srand((int) time((time_t *) NULL));
    to64(&salt[0], rand(), 8);
    salt[8] = '\0';

#ifdef __Win32__
    MD5Encode((char *)pw, (char *)salt, cpw, sizeof(cpw));
#else
    crpw = (char *)crypt(pw, salt); // cpw is crypt of password
    crpwLen = ::strlen(crpw);
    strncpy(cpw, crpw, crpwLen);
    cpw[crpwLen] = '\0';
#endif
    
    dpw = (char *)Digest(user, pw, realm); // dpw is digest of password
    
    qtss_fprintf(f, "%s:%s:%s\n", user, cpw, dpw);
    free(pw); // Do after cpw and dpw are used. 
}
Esempio n. 4
0
int main(int argc, char* argv[]) {
  Arguments args;
  GlobalState state;
  state.num_locking_processes = 0;
  state.p_locking_processes = NULL;

  state.appHWnd = FindConsoleHandle();

  kExitCode exit_code = ParseArguments(argc, argv, &args);
  if (exit_code == kUserNoFiles) {
    PrintHelp();
    fprintf(stderr, "\nError: No filename(s) specified.");
    return (exit_code);
  } else if (exit_code == kUserTooManyFiles) {
    fprintf(stderr, "\nError: Too many filenames specified, max is 32.\n");
    return (exit_code);
  } else if (exit_code != kSuccess) {
    return (exit_code);
  }

  exit_code = InterfaceStateInit(&args, &state.if_state);
  if (exit_code != kSuccess) {
    CleanupAndExit(&args, &state, exit_code);
  }

  if (args.action == kActionHelpOnly) {
    PrintHelp();
    return (kSuccess);
  }

  do {
    kExitCode update_result = UpdateState(&args, &state);
    if (update_result == kFailEnumProc) {
      fprintf(stderr, "\nError: Failed to enumerate processes.\n");
      return (kFailEnumProc);
    } else if (update_result == kSuccessNoReplacements) {
      dbg_printf("Success: No replacement files found.\n");
      return (kSuccess);
    }

  } while (1);

  return (kSuccess);
}
Esempio n. 5
0
void 
RespondExitCB(
        Widget w,
        XtPointer client,
        XtPointer call)
{
  char buf[REQUEST_LIM_MAXLEN];
  ResponseExit *r = (ResponseExit *)buf;

#ifdef VG_TRACE
  vg_TRACE_EXECUTION("main:  entered RespondExitCB ...");
#endif /* VG_TRACE */

  r->hdr.opcode = REQUEST_OP_EXIT;
  r->hdr.reserved = 0;
  r->hdr.length = sizeof(*r);

  TellRequester(buf, (size_t) r->hdr.length);

  CleanupAndExit(NULL, NOTIFY_OK);
}
Esempio n. 6
0
void
RespondLangCB( Widget w, XtPointer client, XtPointer call)
{
  XtSetArg(argt[0], XmNset, True);
  XtSetValues(w, argt, 1);

#ifdef VG_TRACE
  vg_TRACE_EXECUTION("main:  entered RespondLangCB ...");
#endif /* VG_TRACE */

  if (amChooser) {
	/** this is probably not the ideal way to do this **/
	/** but it does work ok.                          **/
	/** notice the related code in chooser.c at the   **/
	/** beginning of main.                            **/
	char buff[128];
	if (XmToggleButtonGadgetGetState(w)) {
	    strcpy(buff, "LANG="); 
	    strcat(buff, client);
	    putenv(buff);
	    execv(orig_argv[0], orig_argv);
	}
  } else {
    char buf[REQUEST_LIM_MAXLEN];
    ResponseLang *r = (ResponseLang *)buf;
    char *p;
  
    r->hdr.opcode = REQUEST_OP_LANG;
    r->hdr.reserved = 0;
    r->offLang = sizeof(*r);
    p = ((char *)(r)) + r->offLang;
    strcpy(p, XmToggleButtonGadgetGetState(w) ? client : "default");
    r->hdr.length = sizeof(*r) + strlen(p) + 1;

    TellRequester(buf, (size_t) r->hdr.length);
 
    CleanupAndExit(NULL, NOTIFY_LANG_CHANGE);
  }
}
/* Allocates memory; remember to delete it afterwards */
char* GetTempFileAtPath(char* templatePath, int templatePathLength)
{
	char* tempFile = new char[templatePathLength];
	memcpy(tempFile, templatePath, templatePathLength);
	char* theResultTempFile = NULL;
	
#ifdef __Win32__	
	theResultTempFile = mktemp(tempFile);
#else	
	int theErr = mkstemp(tempFile);
	if (theErr != -1)
		theResultTempFile = tempFile;
#endif

	if (theResultTempFile == NULL)
	{
		char buffer[kErrorStrSize];
		qtss_fprintf(stderr, "Could not create a temp file at %s. (err=%d:%s)\n", tempFile, errno,  qtss_strerror(errno, buffer, sizeof(buffer)));
		CleanupAndExit();
	}
	
	return theResultTempFile;
}
int main(int argc, char *argv[])
{
    FILE *usersFilePtr = NULL, *tempUsersFilePtr = NULL, *passFilePtr = NULL, *groupsFilePtr = NULL;
    //char line[MAX_STRING_LEN + 1];
    char line[MAX_LINE_LEN];
    char lineFromFile[MAX_LINE_LEN];
    char usernameFromFile[MAX_STRING_LEN + 1];
    char realmFromFile[MAX_STRING_LEN + 1];
    int found;
    int result;
    static char choice[81];

    int doCreateNewFile = 0;
    int doDeleteUser = 0;
	int addUserToGroup = 0;
	int deleteUserFromGroup = 0;
	int createGroup = 0;
	int deleteGroup = 0;
    int confirmPotentialDamage = 1;
    char* qtusersFilePath = NULL;
	char* qtgroupsFilePath = NULL;
    char* userName = NULL;
	char* groupName = NULL;
    char* realmString = NULL;
    char* password = NULL;
    char* passwordFilePath = NULL;
    int ch;
    extern char* optarg;
    extern int optind;

	/* Read command line arguments */
    while ((ch = getopt(argc, argv, "f:cg:r:p:P:A:D:C:R:dFhv?")) != EOF)
    {
        switch(ch) 
        {

            case 'f':
                    qtusersFilePath = CopyString(optarg);
            break;
			
            case 'c':
                    doCreateNewFile = 1;
            break;
			
            case 'g':
                    qtgroupsFilePath = CopyString(optarg);
            break;
			
            case 'r':
                    realmString = CopyString(optarg);
                    if (::strlen(realmString) > MAX_STRING_LEN)
                    {
                        qtss_fprintf(stderr, "Realm cannot have more than %d characters.\n", MAX_STRING_LEN);
                        qtss_printf("Exiting! \n");
                        exit(1);
                    }
            break;

            case 'p':
                    password = CopyString(optarg);
					::memset(optarg, 0, ::strlen(optarg));
					
                    if (::strlen(password) > MAX_PASSWORD_LEN)
                    {
                        qtss_fprintf(stderr, "Password cannot have more than %d characters.\n", MAX_PASSWORD_LEN);
                        qtss_printf("Exiting! \n");
                        exit(1);
                    }
            break;

            case 'P':
                    passwordFilePath = CopyString(optarg);
            break;

            case 'A':
                    groupName = CopyString(optarg);
					addUserToGroup = 1;
            break;

            case 'D':
                    groupName = CopyString(optarg);
					deleteUserFromGroup = 1;
            break;

            case 'C':
                    groupName = CopyString(optarg);
					createGroup = 1;
            break;

            case 'R':
                    groupName = CopyString(optarg);
					deleteGroup = 1;
            break;			

            case 'd':
                    doDeleteUser = 1;
            break;
			
            case 'F':
                    confirmPotentialDamage = 0;
            break;

        case 'h':
        case 'v':
            case '?':
            default:
                usage(); 
            break;
        }
    }

	/* If password is to be read from a file, check validity of the password */
	if ((password == NULL) && (passwordFilePath != NULL))
    {
		if ((passFilePtr = fopen(passwordFilePath, "r")) != NULL ) 
		{
			char passline[MAX_STRING_LEN];
			char passFromFile[MAX_STRING_LEN];
			int passLen = 0;
			
			::memset(passline, 0, MAX_STRING_LEN);
			::memset(passFromFile, 0, MAX_STRING_LEN);
			
			GetLine(passline, MAX_STRING_LEN, passFilePtr);
	
			if (passline[0] == '\'')        // if it is single quoted, read until the end single quote
				GetWord(passFromFile, (passline + 1), '\'');
			else if (passline[0] == '"')        // if it is double quoted, read until the end double quote
				GetWord(passFromFile, (passline + 1), '"');
			else                    // if it is not quoted, read until the first whitespace
				GetWord(passFromFile, passline, ' ');
				
			passLen = ::strlen(passFromFile);
				
			if (passLen == 0)
			{
				qtss_fprintf(stderr, "Password in file %s is blank.\n", passwordFilePath);
				qtss_printf("Exiting! \n");
				exit(1);
			}
			else if (passLen > MAX_PASSWORD_LEN)
			{
				qtss_fprintf(stderr, "Password in file %s has more than %d characters. Cannot accept password.\n", passwordFilePath, MAX_PASSWORD_LEN);
				qtss_printf("Exiting! \n");
				exit(1);
			}
			else
				password = CopyString(passFromFile);

            fclose(passFilePtr);
        }
    }

    /* deleting a user and (creating a file or setting a password) don't make sense together */
    if ( doDeleteUser && (doCreateNewFile || password != NULL) )
    {
		qtss_fprintf(stderr, "Cannot use the -c option (to create the file) with the -d option (to delete the user).\n");
		qtss_printf("Exiting! \n");
        usage();
    }

    /* realm name only makes sense when creating a new password file */
    if ( !doCreateNewFile && (realmString != NULL) )
    {
		qtss_fprintf(stderr, "Can use the -r option only with the -c option (when creating the file).\n");
		qtss_printf("Exiting! \n");
		usage();
    }

	/* group name checks */
	if (groupName != NULL) 
	{
		/* check length < MAX_STRING_LEN */
		if (::strlen(groupName) > MAX_STRING_LEN)
		{
			qtss_fprintf(stderr, "Group name cannot have more than %d characters.\n", MAX_STRING_LEN);
			qtss_printf("Exiting! \n");
			exit(1);
		}	
		
		/* check for : */
        if (strchr(groupName, ':') != NULL) 
        {
            qtss_printf("Group name cannot contain a ':' character.\n");
			qtss_printf("Exiting! \n");
			exit(1);
        }
		
		/* can't add user to group and delete user from a group at the same time */
		if (addUserToGroup && deleteUserFromGroup)
        {
            qtss_printf("Cannot add to or delete from a group at the same time (use either -A or -D option, not both!).\n");
			qtss_printf("Exiting! \n");
			exit(1);
        }
		
		/* can't create and delete group at the same time */
		if (createGroup && deleteGroup)
        {
            qtss_printf("Cannot create new group and delete group at the same time (use either -C or -R option, not both!).\n");
			qtss_printf("Exiting! \n");
			exit(1);
        }
	}

	/* Read in the username */
    if (argv[optind] != NULL)
    {
		/* If group needs to be created or deleted, username will be ignored. */
		if (createGroup || deleteGroup)
		{
			qtss_fprintf(stderr, "Warning: username cannot be specified with -C or -R option and will be ignored!\n");
		}
		else
		{
			userName = CopyString(argv[optind]);
			
			/* check length < MAX_STRING_LEN */		
			if (::strlen(userName) > MAX_STRING_LEN)
			{
			qtss_fprintf(stderr, "Username cannot have more than %d characters.\n", MAX_STRING_LEN);
			qtss_printf("Exiting! \n");
			exit(1);
			}
		}
    }
    else
	{
		/* Exit if username is not given, unless a group has to be created or deleted. */
		if (!createGroup && !deleteGroup)
		{
			qtss_fprintf(stderr, "Username not given!\n");
			qtss_printf("Exiting! \n");
			usage();
		}
    }

    if (confirmPotentialDamage && doDeleteUser)
    {
        qtss_printf("Delete user %s (will also delete user from groups in the groups file)? y or n [y] ", userName);
        fgets( (char*)&choice, 80, stdin);
        if( choice[0] == 'n' || choice[0] == 'N' ) 
            exit(0);
    }

    if (qtusersFilePath == NULL)
    {
        qtusersFilePath = new char[strlen(kDefaultQTPasswdFilePath)+1];
        strcpy(qtusersFilePath, kDefaultQTPasswdFilePath);
    }

    if (qtgroupsFilePath == NULL)
    {
        qtgroupsFilePath = new char[strlen(kDefaultQTGroupsFilePath)+1];
        strcpy(qtgroupsFilePath, kDefaultQTGroupsFilePath);
    }
	
    if (realmString  == NULL)
    {
        char* kDefaultRealmString = "Streaming Server";

        realmString = new char[strlen(kDefaultRealmString)+1];
        strcpy(realmString, kDefaultRealmString);
    }

    
    tempUsersFile = NULL;
	tempGroupsFile = NULL;
	
#ifndef __Win32__
    signal(SIGINT, (void(*)(int))CleanupAndExit);
    //create file with owner RW permissions only
    umask(S_IRWXO|S_IRWXG);
#endif

    if (doCreateNewFile)
    {
        if (confirmPotentialDamage)
            if( (usersFilePtr = fopen(qtusersFilePath, "r")) != NULL ) 
            {
                fclose(usersFilePtr);
    
                qtss_printf("File already exists. Do you wish to overwrite it? y or n [y] ");
                fgets( (char*)&choice, 80, stdin);
                if( choice[0] == 'n' || choice[0] == 'N' ) 
                    CleanupAndExit();
                    
            }

        //create new file or truncate existing one to 0
        if ( (usersFilePtr = fopen(qtusersFilePath, "w")) == NULL)
        {   
			char buffer[kErrorStrSize];
            qtss_fprintf(stderr, "Could not open password file %s for writing. (err=%d %s)\n", qtusersFilePath, errno, qtss_strerror(errno, buffer, sizeof(buffer)));
            perror("fopen");
            CleanupAndExit();
        }

        qtss_printf("Creating password file for realm %s.\n", realmString);

        //write the realm into the file
        qtss_fprintf(usersFilePtr, "realm %s\n", realmString);

        fclose(usersFilePtr);
	    SetPrivileges(qtusersFilePath);


    }

#ifdef __Win32__
    char separator = '\\';
#else
    char separator = '/';
#endif
	char* tmpFile = "tmp.XXXXXX";
	char* alternateTempPath = "./tmp.XXXXXX";
    char* tempFilePath;
	int	tempFilePathLength = 0;
    char* lastOccurOfSeparator = strrchr(qtusersFilePath, separator);
    int pathLength = strlen(qtusersFilePath);
	
    if(lastOccurOfSeparator != NULL) 
    {
		int filenameLength = ::strlen(lastOccurOfSeparator) + sizeof(char);
		tempFilePathLength = pathLength - filenameLength + sizeof(char) + ::strlen(tmpFile);
		
		tempFilePath = new char[tempFilePathLength];
		memcpy(tempFilePath, qtusersFilePath, (pathLength - filenameLength));
		memcpy(tempFilePath + (pathLength - filenameLength), tmpFile, ::strlen(tmpFile));
		tempFilePath[pathLength - filenameLength + ::strlen(tmpFile)] = '\0';
		
		/* Get temp users file path name */
		if (!createGroup && !deleteGroup)
			tempUsersFile = GetTempFileAtPath(tempFilePath, tempFilePathLength);

		/* Get temp groups file path name */		
		if ((groupName != NULL) || doDeleteUser)
			tempGroupsFile = GetTempFileAtPath(tempFilePath, tempFilePathLength);
		
		delete [] tempFilePath;
    }
    else 
    {
		if (!createGroup && !deleteGroup)
			tempUsersFile = GetTempFileAtPath(alternateTempPath, ::strlen(alternateTempPath));
		if ((groupName != NULL) || doDeleteUser)
			tempGroupsFile = GetTempFileAtPath(alternateTempPath, ::strlen(alternateTempPath));
	}
		
	if ((groupName != NULL) && !(groupsFilePtr = fopen(qtgroupsFilePath, "r")))
	{
		char buffer[kErrorStrSize];
		qtss_fprintf(stderr, "Could not open groups file %s to manipulate groups file. (err=%d:%s)\n", qtgroupsFilePath, errno,  qtss_strerror(errno, buffer, sizeof(buffer)));
				
		//create new file
        if ( (groupsFilePtr = fopen(qtgroupsFilePath, "w")) == NULL)
        {   
			char buffer[kErrorStrSize];
            qtss_fprintf(stderr, "Could not create a new groups file %s either. (err=%d %s)\n", qtgroupsFilePath, errno, qtss_strerror(errno, buffer, sizeof(buffer)));
			CleanupAndExit();
        }
		else
			qtss_printf("Created new groups file %s.\n", qtgroupsFilePath);

        fclose(groupsFilePtr);
	    SetPrivileges(qtgroupsFilePath);
	}
	
	if (createGroup)
	{
		AddOrDeleteGroup(1, groupName, qtgroupsFilePath, tempGroupsFile);
		qtss_printf("Created new group %s\n", groupName);
		return 0;
	}
	
	if (deleteGroup)
	{
		AddOrDeleteGroup(0, groupName, qtgroupsFilePath, tempGroupsFile);
		qtss_printf("Deleted group %s\n", groupName);
		return 0;
	}
	
    if (!(tempUsersFilePtr = fopen(tempUsersFile, "w"))) 
    {   
        char buffer[kErrorStrSize];
        qtss_printf("failed\n");
        qtss_fprintf(stderr, "Could not open temp users file. (err=%d %s)\n", errno,  qtss_strerror(errno, buffer, sizeof(buffer)));
		CleanupAndExit();
    }
	
    if (!(usersFilePtr = fopen(qtusersFilePath, "r")))
    {   
        char buffer[kErrorStrSize];
        qtss_fprintf(stderr, "Could not open passwd file %s for reading. (err=%d:%s)\n", qtusersFilePath, errno,  qtss_strerror(errno, buffer, sizeof(buffer)));
        qtss_fprintf(stderr, "Use -c option to create new one.\n");
		CleanupAndExit();
    }

    // Get the realm from the first line
    while (!(GetLine(line, MAX_LINE_LEN, usersFilePtr))) 
    {
        if ((line[0] == '#') || (!line[0]))
        {
            PutLine(tempUsersFilePtr, line);
            continue;
        }
        else
        {
            // line is "realm somename"
            if( strncmp(line, "realm", strlen("realm")) != 0 )
            {
                    qtss_fprintf(stderr, "Invalid users file.\n");
                    qtss_fprintf(stderr, "The first non-comment non-blank line must be the realm line\n");
                    qtss_fprintf(stderr, "The file may have been tampered manually!\n");				
					CleanupAndExit();
            }
            strcpy(realmFromFile ,line + strlen("realm")+1); 
            PutLine(tempUsersFilePtr, line);
            break;  
        }
    }
    // Look for an existing entry with the username
    found = 0;
    while (!(GetLine(line, MAX_LINE_LEN, usersFilePtr))) 
    {
        //write comments and blank lines out to temp file
        if (found || (line[0] == '#') || (line[0] == 0)) 
        {
            PutLine(tempUsersFilePtr, line);
            continue;
        }
        strcpy(lineFromFile, line);
        GetWord(usernameFromFile, lineFromFile, ':');

        //if not the user we're looking for, write the line out to the temp file
        if (strcmp(userName, usernameFromFile) != 0) 
        {
            PutLine(tempUsersFilePtr, line);
            continue;
        }
        else 
        {
            if (doDeleteUser)
            {   //to delete a user - just don't write it out to the temp file
                qtss_printf("Deleting user %s\n", userName);
				//delete user from all groups in the group file
				qtss_printf("Deleting user %s from all groups\n", userName);
				AddOrDeleteUserFromGroup(0, userName, NULL, qtgroupsFilePath, tempGroupsFile);
				
            }
            else
            {
				if (addUserToGroup)
				{
					PutLine(tempUsersFilePtr, line);
					
					qtss_printf("Adding user %s to group %s\n", userName, groupName);
					AddOrDeleteUserFromGroup(1, userName, groupName, qtgroupsFilePath, tempGroupsFile);
				}
				else if (deleteUserFromGroup)
				{
					PutLine(tempUsersFilePtr, line);
					
					qtss_printf("Deleting user %s from group %s\n", userName, groupName);
					AddOrDeleteUserFromGroup(0, userName, groupName, qtgroupsFilePath, tempGroupsFile);
				}
				else
				{
					qtss_printf("Changing password for user %s\n", userName);
					if(password != NULL)
						AddPasswordWithoutPrompt(userName, password, realmFromFile, tempUsersFilePtr);
					else 
						AddPassword(userName, realmFromFile, tempUsersFilePtr);
				}
            }
            found = 1;
        }
    }
    
    if (!found) 
    {
        if (doDeleteUser)
        {
            qtss_printf("Username %s not found in users file.\n", userName);
			
			//delete user from all groups in the group file
			qtss_printf("Deleting user %s from all groups if found in groups file\n", userName);
			AddOrDeleteUserFromGroup(0, userName, NULL, qtgroupsFilePath, tempGroupsFile);
			CleanupAndExit();
        }

        /* check for : in name before adding user */
        if(strchr(userName, ':') != NULL) 
        {
            qtss_printf("Username cannot contain a ':' character.");
			CleanupAndExit();
        }
    
        qtss_printf("Adding userName %s\n", userName);
        if(password != NULL)
            AddPasswordWithoutPrompt(userName, password, realmFromFile, tempUsersFilePtr);
        else 
            AddPassword(userName, realmFromFile, tempUsersFilePtr);
			
		if (addUserToGroup)
		{
			qtss_printf("Adding user %s to group %s\n", userName, groupName);
			AddOrDeleteUserFromGroup(1, userName, groupName, qtgroupsFilePath, tempGroupsFile);
		}
		else if (deleteUserFromGroup)
		{
			qtss_printf("Deleting user %s from group %s\n", userName, groupName);
			AddOrDeleteUserFromGroup(0, userName, groupName, qtgroupsFilePath, tempGroupsFile);
		}
    }
    	
    fclose(usersFilePtr);
    fclose(tempUsersFilePtr);
    
    // Remove old file and change name of temp file to match new file
    remove(qtusersFilePath);
    
    result = rename(tempUsersFile, qtusersFilePath);
    if(result != 0)
	{
        perror("rename failed with error");
		CleanupAndExit();
	}
	SetPrivileges(qtusersFilePath);

    return 0;
}
static void AddOrDeleteGroup(int add, char *groupName, char *inGroupsFilePath, char *inTempGroupsFilePath)
{
    char line[MAX_LINE_LEN];
    char lineFromFile[MAX_LINE_LEN];
    char groupNameFromFile[MAX_STRING_LEN + 1];
    bool foundGroup = false;
	FILE *groupsFilePtr, *tempGroupsFilePtr;
	bool addedGroup = false;
	
    if (!(groupsFilePtr = fopen(inGroupsFilePath, "r")))
    {   
		if (add)
		{
			char buffer[kErrorStrSize];
			qtss_fprintf(stderr, "Could not open groups file %s for reading. (err=%d:%s)\n", inGroupsFilePath, errno,  qtss_strerror(errno, buffer, sizeof(buffer)));
			CleanupAndExit();
		}
		else
			return;
    }
		
	if (!(tempGroupsFilePtr = fopen(inTempGroupsFilePath, "w"))) 
    {   
        char buffer[kErrorStrSize];
        qtss_fprintf(stderr, "Could not open temp groups file. (err=%d %s)\n", errno,  qtss_strerror(errno, buffer, sizeof(buffer)));
		CleanupAndExit();
    }
	
	while (!(GetLine(line, MAX_LINE_LEN, groupsFilePtr))) 
    {
        //write comments and blank lines out to temp file
        if (foundGroup || (line[0] == '#') || (line[0] == 0)) 
        {
            PutLine(tempGroupsFilePtr, line);
            continue;
        }
		
        strcpy(lineFromFile, line);
		EatWhitespace(lineFromFile);
        GetWord(groupNameFromFile, lineFromFile, ':');

        //if it's not the group we're looking for, write the line out to the temp file
        if ((groupName != NULL) && strcmp(groupName, groupNameFromFile) != 0) 
        {
            PutLine(tempGroupsFilePtr, line);
            continue;
        }
        else if (add) // if we are trying to add the group and it already exists, leave it in
		{
			PutLine(tempGroupsFilePtr, line);
			addedGroup = true;
		}
		
		foundGroup = true;
	}		
	
	if (add && !addedGroup)
	{
		PutWord(tempGroupsFilePtr, groupName, ':');
		fputc('\n', tempGroupsFilePtr);
	}
							
	fclose(tempGroupsFilePtr);
	fclose(groupsFilePtr);
	
    // Rename the temp groups file to the groups file
    //remove(qtusersFilePath);
    
    if (rename(inTempGroupsFilePath, inGroupsFilePath) != 0)
	{
        perror("rename failed with error");
		CleanupAndExit();
	} 
}
Esempio n. 10
0
void 
MenuItemCB( Widget w, XtPointer client_data, XtPointer call_data )
{
	int i;
    	char     *logoFile;
    	char     *logoName;
	char 	*temp_p;
	char 	temp[MAXPATHLEN];

#ifdef VG_TRACE
    vg_TRACE_EXECUTION("main:  entered MenuItemCB ...");
#endif /* VG_TRACE */

    session_selected = True;

    switch ( (int) client_data) {

    case OB_RESTART_SERVER:
	CleanupAndExit(NULL, NOTIFY_RESTART);
	break;

    case OB_NO_WINDOWS:
	CleanupAndExit(NULL, NOTIFY_NO_WINDOWS);
	break;

    case OB_COPYRIGHT:
	_DtShowDialog(copyright, NULL);
	break;

    case OB_ALT_DTS:
    case OB_FAILSAFE:
    case OB_DTLITE:
    case OB_DT: 
    case OB_LAST_DT:
	/*
	 * set the label on the dt_label widget..
	 */ 

	if(w != options_last_dt) {
          XtSetArg(argt[0], XmNlabelString, &xmstr);
          XtGetValues(w, argt, 1);

          XtSetArg(argt[0], XmNlabelString, xmstr);
          XtSetValues(dt_label, argt, 1);
	}
	else
	  ClearDtlabel();

        i = 0;
        XtSetArg(argt[i], XmNuserData,          &logoFile          ); i++;
        XtGetValues(w, argt, i);

        /* 
	 * remove trailing spaces 
	 */
	if(strchr(logoFile,' '))
            temp_p = strtok(logoFile," ");	
	else
	    temp_p = logoFile;
 
        logoName = _DtGetIconFileName(DefaultScreenOfDisplay(dpyinfo.dpy),
                          temp_p, NULL, NULL, 0);
 
        if (logoName == NULL) {
           LogError( 
	     ReadCatalog(MC_LOG_SET,MC_LOG_NO_LOGOBIT,MC_DEF_LOG_NO_LOGOBIT),
                             logoFile);
           logoFile = NULL;
        }
        i = 0;
        XtSetArg(argt[i], XmNimageName, logoName); i++;
        XtSetValues(logo_pixmap, argt, i);

	/*
	 *  Clear Dt toggles...
	 */
	ClearDtButtons();

	/* 
	 * set the selected toggle button...
	 */
        XtSetArg(argt[0], XmNset, True);
        XtSetValues(w, argt, 1);

        SetDefaultDt(w);

	/*
	 *  return focus to name/password widgets...
	 */
	 
	if ( focusWidget != NULL)
	    ProcessTraversal(focusWidget, XmTRAVERSE_CURRENT);

	break;
    }

}