Esempio n. 1
0
NETDB_DEFINE_CONTEXT
/* Make the CLIB Inet stuff link */
#include <netinet/in.h>
#include <arpa/inet.h>
NETINET_DEFINE_CONTEXT

int netware_init ( void )
{
    int rc = 0;
    unsigned int myHandle = GetNLMHandle();
    /* import UnAugmentAsterisk dynamically for NW4.x compatibility */
    void (*pUnAugmentAsterisk)(int) = (void(*)(int))
                                      ImportSymbol(myHandle, "UnAugmentAsterisk");
    /* import UseAccurateCaseForPaths dynamically for NW3.x compatibility */
    void (*pUseAccurateCaseForPaths)(int) = (void(*)(int))
                                            ImportSymbol(myHandle, "UseAccurateCaseForPaths");
    if(pUnAugmentAsterisk)
        pUnAugmentAsterisk(1);
    if(pUseAccurateCaseForPaths)
        pUseAccurateCaseForPaths(1);
    UnimportSymbol(myHandle, "UnAugmentAsterisk");
    UnimportSymbol(myHandle, "UseAccurateCaseForPaths");
    /* set long name space */
    if((SetCurrentNameSpace(4) == 255)) {
        rc = 1;
    }
    if((SetTargetNameSpace(4) == 255)) {
        rc = rc + 2;
    }
    return rc;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    FILE *tfp, *f;
    char user[MAX_STRING_LEN];
    char realm[MAX_STRING_LEN];
    char line[MAX_STRING_LEN];
    char l[MAX_STRING_LEN];
    char w[MAX_STRING_LEN];
    char x[MAX_STRING_LEN];
    char command[MAX_STRING_LEN];
    int found;

    tn = NULL;
    signal(SIGINT, (void (*)(int)) interrupted);
    if (argc == 5) {
	if (strcmp(argv[1], "-c"))
	    usage();
#ifdef NETWARE
    UnAugmentAsterisk(TRUE);
    SetCurrentNameSpace(NW_NS_LONG);
    SetTargetNameSpace(NW_NS_LONG);
#endif
	if (!(tfp = fopen(argv[2], "w"))) {
	    fprintf(stderr, "Could not open passwd file %s for writing.\n",
		    argv[2]);
	    perror("fopen");
	    exit(1);
	}
	printf("Adding password for %s in realm %s.\n", argv[4], argv[3]);
	add_password(argv[4], argv[3], tfp);
	fclose(tfp);
	exit(0);
    }
    else if (argc != 4)
	usage();

    tn = tmpnam(NULL);
    if (!(tfp = fopen(tn, "w"))) {
	fprintf(stderr, "Could not open temp file.\n");
	exit(1);
    }

    if (!(f = fopen(argv[1], "r"))) {
	fprintf(stderr,
		"Could not open passwd file %s for reading.\n", argv[1]);
	fprintf(stderr, "Use -c option to create new one.\n");
	exit(1);
    }
    ap_cpystrn(user, argv[3], sizeof(user));
    ap_cpystrn(realm, argv[2], sizeof(realm));

    found = 0;
    while (!(getline(line, MAX_STRING_LEN, f))) {
	if (found || (line[0] == '#') || (!line[0])) {
	    putline(tfp, line);
	    continue;
	}
	strcpy(l, line);
	getword(w, l, ':');
	getword(x, l, ':');
	if (strcmp(user, w) || strcmp(realm, x)) {
	    putline(tfp, line);
	    continue;
	}
	else {
	    printf("Changing password for user %s in realm %s\n", user, realm);
	    add_password(user, realm, tfp);
	    found = 1;
	}
    }
    if (!found) {
	printf("Adding user %s in realm %s\n", user, realm);
	add_password(user, realm, tfp);
    }   
    fclose(f);
    fclose(tfp);
#ifndef NETWARE
#if defined(OS2) || defined(WIN32)
    sprintf(command, "copy \"%s\" \"%s\"", tn, argv[1]);
#else
    sprintf(command, "cp %s %s", tn, argv[1]);
#endif
    system(command);
#else
    if (!(tfp = fopen(tn, "r"))) {
    fprintf(stderr, "Could not open temp file.\n");
    exit(1);
    }
    
    if (!(f = fopen(argv[1], "w"))) {
    fprintf(stderr, "Could not open %s.\n", argv[1]);    
    exit(1);    
    }
    
    copy_file(f, tfp);
#endif
    unlink(tn);
    return 0;
}
Esempio n. 3
0
void Restore (NWCONN_HANDLE ConnHandle, char* FileName, char* Logfilename)
{
	char 		Line 		[1024];
	char* 		Next;
	char 		Buffer 		[512];
	FILE* 		BackupFile;
	FILE*		Logfile;
	char  		FirstParam 	[512];
	char  		Rights 		[12];
	char  		Object 		[300];
	int   		ArgNo;
	char  		Op 		[8];
	NWDSCCODE 	res;
	BYTE 		OldNameSpace;

	// save the default namespace
	OldNameSpace = SetCurrentNameSpace (NW_NS_LONG);

	// attempt to open the backup file
	if ((BackupFile = fopen (FileName, "r")) == NULL)
		printf ("Couldn\'t open file: %s\n", FileName);
	else
	{
		if (Logfilename)
		{
			if ((Logfile = fopen (Logfilename, "w")) == NULL)
			{
				printf ("Couldn't open %s\n", Logfilename);
				Logfile = NULL;
			}
		}
		else
			Logfile = NULL;
		
		// read file line by line - also, check that the NLM hasn't been terminated
		while ((!feof (BackupFile)) && (!NlmExiting))
		{
			fgets (Line, 1024, BackupFile);
			if (!feof (BackupFile))
			{
				Next = Line;
				ArgNo = 0;

				// use GetParams to iteratively get the equivalent argvs
				while (strcmp ((Next = GetParam (Next, Buffer, 512)), "") != 0 || strcmp (Buffer, "") != 0)
				{
					// copy string depending on the argument number
					
					ArgNo++;
					if (ArgNo == 1)
					{
						if (stricmp (Buffer, "RIGHTS") != 0 && stricmp (Buffer, "cx") != 0)
							break;
						else
							strncpy (Op, Buffer, 8);
					}
					
					else if (ArgNo == 2)
						strcpy (FirstParam, Buffer);
					
					else if (ArgNo == 3)
					{
						strncpy (Rights, Buffer, 12);
						Rights [11] = 0;
					}
					
					else if (ArgNo == 4)
					{
						if (strncmp (Buffer, "/NAME=", 6) == 0 || strncmp (Buffer, "/name=", 6) == 0)
							TrimQuotes (Object, Buffer, MAX_DN_CHARS);
						else if (stricmp (Buffer, "/F") == 0)
							strcpy (Object, "/F");
						else
							strcpy (Object, "");
						
					}
					
					else
						break;
				}
				
				// if the syntax is valid call the appropriate function to 
				// set trustee rights or IRFs
				
				if (stricmp (Op, "RIGHTS") ==0 && ArgNo == 4)
				{
					if (strncmp (Object, "/F", 2) == 0 || strncmp (Object, "/f", 2) == 0)
					{
						// printf ("IRF: %s, %s\n", FirstParam, Rights);
						// if (Clear != 0)
						//	InheritedRights (ConnHandle, 0, FirstParam, NW_NS_LONG, "RWCFEMA");
		                                res = InheritedRights (ConnHandle, 0, FirstParam, NW_NS_LONG, Rights);
						DisplayOutput (FirstParam, Rights, "/F", res, Logfile);
					}

					if (strncmp (Object, "/NAME=", 6) == 0 || strncmp (Object, "/name=", 6) == 0)
					{
						// printf ("Rights: %s, %s, %s\n", FirstParam, Rights, Object);
						// if (Clear != 0)
						//	TrusteeRights (ConnHandle, 0, FirstParam, NW_NS_LONG, Object+6, "REM");
	                                        res = TrusteeRights (ConnHandle, 0, FirstParam, NW_NS_LONG, Object+6, Rights);
						DisplayOutput (FirstParam, Rights, Object+6, res, Logfile);
					}
				}

				// code to change context
				if (stricmp (Op, "cx") == 0 && ArgNo == 2)
				{
					if ((res = NWDSSetContext (NDSContext, DCK_NAME_CONTEXT, FirstParam)) != 0)
						printf ("NWDSSetContext returned: %d\n", res);
				}
					
			}
		}
		
		// close the file and restore the original name space
		fclose (BackupFile);
		if (Logfile)
			fclose (Logfile);
		
		SetTargetNameSpace (OldNameSpace);
	}
}
Esempio n. 4
0
/*
 * Let's do it.  We end up doing a lot of file opening and closing,
 * but what do we care?  This application isn't run constantly.
 */
int main(int argc, char *argv[])
{
    FILE *ftemp = NULL;
    FILE *fpw = NULL;
    char user[MAX_STRING_LEN];
    char password[MAX_STRING_LEN];
    char record[MAX_STRING_LEN];
    char line[MAX_STRING_LEN];
    char pwfilename[MAX_STRING_LEN];
    char *arg;
    int found = 0;
    int alg = ALG_CRYPT;
    int newfile = 0;
    int nofile = 0;
    int noninteractive = 0;
    int i;
    int args_left = 2;

    tempfilename = NULL;
    signal(SIGINT, (void (*)(int)) interrupted);

    /*
     * Preliminary check to make sure they provided at least
     * three arguments, we'll do better argument checking as 
     * we parse the command line.
     */
    if (argc < 3) {
	return usage();
    }

    /*
     * Go through the argument list and pick out any options.  They
     * have to precede any other arguments.
     */
    for (i = 1; i < argc; i++) {
	arg = argv[i];
	if (*arg != '-') {
	    break;
	}
	while (*++arg != '\0') {
	    if (*arg == 'c') {
		newfile++;
	    }
	    else if (*arg == 'n') {
		nofile++;
		args_left--;
	    }
	    else if (*arg == 'm') {
		alg = ALG_APMD5;
	    }
	    else if (*arg == 's') {
		alg = ALG_APSHA;
	    }
	    else if (*arg == 'p') {
		alg = ALG_PLAIN;
	    }
	    else if (*arg == 'd') {
		alg = ALG_CRYPT;
	    }
	    else if (*arg == 'b') {
		noninteractive++;
		args_left++;
	    }
	    else {
		return usage();
	    }
	}
    }

    /*
     * Make sure we still have exactly the right number of arguments left
     * (the filename, the username, and possibly the password if -b was
     * specified).
     */
    if ((argc - i) != args_left) {
	return usage();
    }
#ifdef NETWARE
    UnAugmentAsterisk(TRUE);
    SetCurrentNameSpace(NW_NS_LONG);
    SetTargetNameSpace(NW_NS_LONG);
#endif
    if (newfile && nofile) {
	fprintf(stderr, "%s: -c and -n options conflict\n", argv[0]);
	return ERR_SYNTAX;
    }
    if (nofile) {
	i--;
    }
    else {
	if (strlen(argv[i]) > (sizeof(pwfilename) - 1)) {
	    fprintf(stderr, "%s: filename too long\n", argv[0]);
	    return ERR_OVERFLOW;
	}
	strcpy(pwfilename, argv[i]);
	if (strlen(argv[i + 1]) > (sizeof(user) - 1)) {
	    fprintf(stderr, "%s: username too long (>%lu)\n", argv[0],
		    (unsigned long)(sizeof(user) - 1));
	    return ERR_OVERFLOW;
	}
    }
    strcpy(user, argv[i + 1]);
    if ((arg = strchr(user, ':')) != NULL) {
	fprintf(stderr, "%s: username contains illegal character '%c'\n",
		argv[0], *arg);
	return ERR_BADUSER;
    }
    if (noninteractive) {
	if (strlen(argv[i + 2]) > (sizeof(password) - 1)) {
	    fprintf(stderr, "%s: password too long (>%lu)\n", argv[0],
		    (unsigned long)(sizeof(password) - 1));
	    return ERR_OVERFLOW;
	}
	strcpy(password, argv[i + 2]);
    }

#ifdef WIN32
    if (alg == ALG_CRYPT) {
	alg = ALG_APMD5;
	fprintf(stderr, "Automatically using MD5 format on Windows.\n");
    }
#elif defined(TPF) || defined(NETWARE)
    if (alg == ALG_CRYPT) {
        alg = ALG_APMD5;
        fprintf(stderr, "Automatically using MD5 format.\n");
     }
#endif

#if (!(defined(WIN32) || defined(TPF) || defined(NETWARE)))
    if (alg == ALG_PLAIN) {
	fprintf(stderr,"Warning: storing passwords as plain text might "
		"just not work on this platform.\n");
    }
#endif
    if (! nofile) {
	/*
	 * Only do the file checks if we're supposed to frob it.
	 *
	 * Verify that the file exists if -c was omitted.  We give a special
	 * message if it doesn't.
	 */
	if ((! newfile) && (! exists(pwfilename))) {
	    fprintf(stderr,
		    "%s: cannot modify file %s; use '-c' to create it\n",
		    argv[0], pwfilename);
	    perror("fopen");
	    exit(ERR_FILEPERM);
	}
	/*
	 * Verify that we can read the existing file in the case of an update
	 * to it (rather than creation of a new one).
	 */
	if ((! newfile) && (! readable(pwfilename))) {
	    fprintf(stderr, "%s: cannot open file %s for read access\n",
		    argv[0], pwfilename);
	    perror("fopen");
	    exit(ERR_FILEPERM);
	}
	/*
	 * Now check to see if we can preserve an existing file in case
	 * of password verification errors on a -c operation.
	 */
	if (newfile && exists(pwfilename) && (! readable(pwfilename))) {
	    fprintf(stderr, "%s: cannot open file %s for read access\n"
		    "%s: existing auth data would be lost on "
		    "password mismatch",
		    argv[0], pwfilename, argv[0]);
	    perror("fopen");
	    exit(ERR_FILEPERM);
	}
	/*
	 * Now verify that the file is writable!
	 */
	if (! writable(pwfilename)) {
	    fprintf(stderr, "%s: cannot open file %s for write access\n",
		    argv[0], pwfilename);
	    perror("fopen");
	    exit(ERR_FILEPERM);
	}
    }

    /*
     * All the file access checks (if any) have been made.  Time to go to work;
     * try to create the record for the username in question.  If that
     * fails, there's no need to waste any time on file manipulations.
     * Any error message text is returned in the record buffer, since
     * the mkrecord() routine doesn't have access to argv[].
     */
    i = mkrecord(user, record, sizeof(record) - 1,
		 noninteractive ? password : NULL,
		 alg);
    if (i != 0) {
	fprintf(stderr, "%s: %s\n", argv[0], record);
	exit(i);
    }
    if (nofile) {
	printf("%s\n", record);
	exit(0);
    }

    /*
     * We can access the files the right way, and we have a record
     * to add or update.  Let's do it..
     */
    errno = 0;
    tempfilename = tmpnam(tname_buf);
    if ((tempfilename == NULL) || (*tempfilename == '\0')) {
	fprintf(stderr, "%s: unable to generate temporary filename\n",
		argv[0]);
	if (errno == 0) {
	    errno = ENOENT;
	}
	perror("tmpnam");
	exit(ERR_FILEPERM);
    }
    ftemp = fopen(tempfilename, "w+");
    if (ftemp == NULL) {
	fprintf(stderr, "%s: unable to create temporary file '%s'\n", argv[0],
		tempfilename);
	perror("fopen");
	exit(ERR_FILEPERM);
    }
    /*
     * If we're not creating a new file, copy records from the existing
     * one to the temporary file until we find the specified user.
     */
    if (! newfile) {
	char scratch[MAX_STRING_LEN];

	fpw = fopen(pwfilename, "r");
	while (! (getline(line, sizeof(line), fpw))) {
	    char *colon;

	    if ((line[0] == '#') || (line[0] == '\0')) {
		putline(ftemp, line);
		continue;
	    }
	    strcpy(scratch, line);
	    /*
	     * See if this is our user.
	     */
	    colon = strchr(scratch, ':');
	    if (colon != NULL) {
		*colon = '\0';
	    }
	    if (strcmp(user, scratch) != 0) {
		putline(ftemp, line);
		continue;
	    }
	    found++;
	    break;
	}
    }
    if (found) {
	fprintf(stderr, "Updating ");
    }
    else {
	fprintf(stderr, "Adding ");
    }
    fprintf(stderr, "password for user %s\n", user);
    /*
     * Now add the user record we created.
     */
    putline(ftemp, record);
    /*
     * If we're updating an existing file, there may be additional
     * records beyond the one we're updating, so copy them.
     */
    if (! newfile) {
	copy_file(ftemp, fpw);
	fclose(fpw);
    }
    /*
     * The temporary file now contains the information that should be
     * in the actual password file.  Close the open files, re-open them
     * in the appropriate mode, and copy them file to the real one.
     */
    fclose(ftemp);
    fpw = fopen(pwfilename, "w+");
    ftemp = fopen(tempfilename, "r");
    copy_file(fpw, ftemp);
    fclose(fpw);
    fclose(ftemp);
    unlink(tempfilename);
    return 0;
}