virtual int challengeLocal(
        const char* username,
        char challengeFilePath[EXECUTOR_BUFFER_SIZE])
    {
        AutoMutex autoMutex(_mutex);

        // Send request header:

        ExecutorRequestHeader header;
        header.code = EXECUTOR_CHALLENGE_LOCAL_MESSAGE;

        if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header))
            return -1;

        // Send request body.

        ExecutorChallengeLocalRequest request;
        memset(&request, 0, sizeof(request));
        Strlcpy(request.user, username, EXECUTOR_BUFFER_SIZE);

        if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request))
            return -1;

        // Receive the response

        ExecutorChallengeLocalResponse response;

        if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response))
            return -1;

        Strlcpy(challengeFilePath, response.challenge, EXECUTOR_BUFFER_SIZE);

        return response.status;
    }
    virtual int authenticatePassword(
        const char* username,
        const char* password)
    {
        AutoMutex autoMutex(_mutex);

        // Send request header:

        ExecutorRequestHeader header;
        header.code = EXECUTOR_AUTHENTICATE_PASSWORD_MESSAGE;

        if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header))
            return -1;

        // Send request body.

        ExecutorAuthenticatePasswordRequest request;
        memset(&request, 0, sizeof(request));
        Strlcpy(request.username, username, EXECUTOR_BUFFER_SIZE);
        Strlcpy(request.password, password, EXECUTOR_BUFFER_SIZE);

        if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request))
            return -1;

        // Receive the response

        ExecutorAuthenticatePasswordResponse response;

        if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response))
            return -1;

        return response.status;
    }
    virtual int renameFile(
        const char* oldPath,
        const char* newPath)
    {
        AutoMutex autoMutex(_mutex);

        // Send request header:

        ExecutorRequestHeader header;
        header.code = EXECUTOR_RENAME_FILE_MESSAGE;

        if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header))
            return -1;

        // Send request body.

        ExecutorRenameFileRequest request;
        memset(&request, 0, sizeof(request));
        Strlcpy(request.oldPath, oldPath, EXECUTOR_BUFFER_SIZE);
        Strlcpy(request.newPath, newPath, EXECUTOR_BUFFER_SIZE);

        if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request))
            return -1;

        // Receive the response

        ExecutorRenameFileResponse response;

        if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response))
            return -1;

        return response.status;
    }
Beispiel #4
0
/* Import the contents of a file in a den archive. */
int
AG_DenImportFile(AG_Den *den, int ind, const char *name, const char *lang,
                 const char *infile)
{
    char buf[8192];
    AG_DenMember *memb;
    FILE *f;
    size_t size, rrv;
    off_t offs;

    offs = AG_Tell(den->buf);
    size = 0;

    if ((f = fopen(infile, "rb")) == NULL) {
        AG_SetError("Unable to open %s", infile);
        return (-1);
    }
    for (;;) {
        rrv = fread(buf, 1, sizeof(buf), f);
        size += rrv;

        if (AG_Write(den->buf, buf, rrv, 1) != 0) {
            return (-1);
        }
    }
    fclose(f);

    memb = &den->members[ind];
    Strlcpy(memb->name, name, sizeof(memb->name));
    Strlcpy(memb->lang, lang, sizeof(memb->lang));
    memb->offs = offs;
    memb->size = size;
    return (0);
}
Beispiel #5
0
/* Issue a verbose message. */
void
AG_Verbose(const char *fmt, ...)
{
	va_list args;

	if (!agVerbose)
		return;

	va_start(args, fmt);
#ifdef _WIN32
	{
		char path[AG_FILENAME_MAX];
		FILE *f;

		Strlcpy(path, agProgName, sizeof(path));
		Strlcat(path, ".out", sizeof(path));
		if ((f = fopen(path, "a")) != NULL) {
			vfprintf(f, fmt, args);
			fclose(f);
		}
	}
#else
	vprintf(fmt, args);
#endif
	va_end(args);
}
Beispiel #6
0
static  Char
filetype(Char *dir, Char *file)
{
    Char    path[PATH_MAX];
    struct stat statb;

    Strlcpy(path, dir, sizeof path/sizeof(Char));
    catn(path, file, sizeof(path) / sizeof(Char));
    if (lstat(short2str(path), &statb) == 0) {
	switch (statb.st_mode & S_IFMT) {
	case S_IFDIR:
	    return ('/');

	case S_IFLNK:
	    if (stat(short2str(path), &statb) == 0 &&	/* follow it out */
		S_ISDIR(statb.st_mode))
		return ('>');
	    else
		return ('@');

	case S_IFSOCK:
	    return ('=');

	default:
	    if (statb.st_mode & 0111)
		return ('*');
	}
    }
    return (' ');
}
Beispiel #7
0
static void
FindWidgets(AG_Widget *wid, AG_Tlist *tl, int depth)
{
	char text[AG_TLIST_LABEL_MAX];
	AG_TlistItem *it;
	AG_Widget *widChld;

	Strlcpy(text, OBJECT(wid)->name, sizeof(text));
	if (AG_OfClass(wid, "AG_Widget:AG_Window:*")) {
		AG_Window *win = (AG_Window *)wid;

		Strlcat(text, " (\"", sizeof(text));
		Strlcat(text, win->caption, sizeof(text));
		Strlcat(text, "\")", sizeof(text));
	}
	it = AG_TlistAddPtr(tl, NULL, text, wid);
	it->depth = depth;
	it->cat = "widget";
	
	if (!TAILQ_EMPTY(&OBJECT(wid)->children)) {
		it->flags |= AG_TLIST_HAS_CHILDREN;
	}
	if ((it->flags & AG_TLIST_HAS_CHILDREN) &&
	    AG_TlistVisibleChildren(tl, it)) {
		OBJECT_FOREACH_CHILD(widChld, wid, ag_widget)
			FindWidgets(widChld, tl, depth+1);
	}
}
Beispiel #8
0
Dir* Dir_Open(const char* path)
{
    Dir* dir;
    char filespec[PAL_MAX_PATH_SIZE];
    
    /* Allocate and zero-fill struct */
    dir = (Dir*)PAL_Calloc(1, sizeof(Dir));
    if (!dir)
        return NULL;

    /* Build files spec */
    {
        if (Strlcpy(filespec, path, sizeof(filespec)) >= PAL_MAX_PATH_SIZE)
            return NULL;

        if (Strlcat(filespec, "/*", sizeof(filespec)) >= PAL_MAX_PATH_SIZE)
            return NULL;
    }

    /* Find first file matching the file spec */
    dir->handle = _findfirst(filespec, &dir->fileinfo);
    if (dir->handle == -1)
    {
        PAL_Free(dir);
        return NULL;
    }

    /* Note that readdir() has not been called yet */
    dir->firstTime = 1;

    return dir;
}
    virtual int validateUser(
        const char* username)
    {
        AutoMutex autoMutex(_mutex);

        // Send request header:

        ExecutorRequestHeader header;
        header.code = EXECUTOR_VALIDATE_USER_MESSAGE;

        if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header))
            return -1;

        // Send request body.

        ExecutorValidateUserRequest request;
        memset(&request, 0, sizeof(request));
        Strlcpy(request.username, username, EXECUTOR_BUFFER_SIZE);

        if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request))
            return -1;

        // Receive the response

        ExecutorValidateUserResponse response;

        if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response))
            return -1;

        return response.status;
    }
Beispiel #10
0
static void
FindWindows(AG_Tlist *tl, AG_Window *win, int depth)
{
	char text[AG_TLIST_LABEL_MAX];
	AG_Window *wSub;
	AG_Widget *wChild;
	AG_TlistItem *it;

	if (strncmp(OBJECT(win)->name, "_Popup-", sizeof("_Popup-")) == 0)
		return;

	Strlcpy(text, win->caption, sizeof(text));
	if (strcmp(OBJECT(win)->name, "generic") == 0) {
		it = AG_TlistAddS(tl, NULL,
		    win->caption[0] != '\0' ? win->caption : _("Untitled"));
	} else {
		it = AG_TlistAdd(tl, NULL, "%s (<%s>)",
		    win->caption[0] != '\0' ? win->caption : _("Untitled"),
		    OBJECT(win)->name);
	}
	it->p1 = win;
	it->depth = depth;
	it->cat = "window";
	if (!TAILQ_EMPTY(&OBJECT(win)->children) ||
	    !TAILQ_EMPTY(&win->subwins)) {
		it->flags |= AG_TLIST_HAS_CHILDREN;
	}
	if ((it->flags & AG_TLIST_HAS_CHILDREN) &&
	    AG_TlistVisibleChildren(tl, it)) {
		TAILQ_FOREACH(wSub, &win->subwins, swins)
			FindWindows(tl, wSub, depth+1);
		OBJECT_FOREACH_CHILD(wChild, win, ag_widget)
			FindWidgets(wChild, tl, depth+1);
	}
}
Beispiel #11
0
    virtual int updateLogLevel(
        const char* logLevel)
    {
        AutoMutex autoMutex(_mutex);

        // Send request header:

        ExecutorRequestHeader header;
        header.code = EXECUTOR_UPDATE_LOG_LEVEL_MESSAGE;

        if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header))
            return -1;

        // Send request body:

        ExecutorUpdateLogLevelRequest request;
        memset(&request, 0, sizeof(request));
        Strlcpy(request.logLevel, logLevel, EXECUTOR_BUFFER_SIZE);

        if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request))
            return -1;

        // Receive the response

        ExecutorUpdateLogLevelResponse response;

        if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response))
            return -1;

        return response.status;
    }
Beispiel #12
0
FMGUI_Dir *
FMGUI_OpenDir(const char *path)
{
	FMGUI_Dir *dir;

	dir = (FMGUI_Dir *) Malloc(sizeof(FMGUI_Dir));
	dir->ents = NULL;
	dir->nents = 0;

#ifdef _WIN32
	{
		char dpath[FMGUI_PATHNAME_MAX];
		HANDLE h;
		WIN32_FIND_DATA fdata;
		DWORD rv;

		Strlcpy(dpath, path, sizeof(dpath));
		Strlcat(dpath, "\\*", sizeof(dpath));
		if ((h = FindFirstFile(dpath, &fdata))==INVALID_HANDLE_VALUE) {
			ReportError1("Invalid file handle (%d)",
			    (int)GetLastError());
			goto fail;
		}
		while (FindNextFile(h, &fdata) != 0) {
			dir->ents = Realloc(dir->ents,
			    (dir->nents+1)*sizeof(char *));
			dir->ents[dir->nents++] = Strdup(fdata.cFileName);
		}
		rv = GetLastError();
		FindClose(h);
		if (rv != ERROR_NO_MORE_FILES) {
			ReportError1("FindNextFileError (%lu)", rv);
			goto fail;
		}
	}
#else /* !_WIN32 */
	{
		DIR *dp;
		struct dirent *dent;
		
		if ((dp = opendir(path)) == NULL) {
			ReportError2("%s: Failed to open directory (%s)",
			    path, strerror(errno));
			goto fail;
		}
		while ((dent = readdir(dp)) != NULL) {
			dir->ents = (char **) Realloc(dir->ents,
			    (dir->nents+1)*sizeof(char *));
			dir->ents[dir->nents++] = strdup(dent->d_name);
		}
		closedir(dp);
	}
#endif /* _WIN32 */

	return (dir);
fail:
	Free(dir);
	return (NULL);
}
Beispiel #13
0
static void
Init(void *p)
{
	VG_TextTool *t = p;

	t->vtIns = NULL;
	Strlcpy(t->text, "<text>", sizeof(t->text));
}
Beispiel #14
0
static void
SetDirectory(AG_FileSelector *fs, const char *pPath)
{
    char path[AG_FILENAME_MAX];

    Strlcpy(path, pPath, sizeof(path));
    AG_FileDlgSetDirectoryS(fs->filedlg, path);
}
Beispiel #15
0
static int
Test(void *obj)
{
	char someString[64], buf[1024];
	AG_TestInstance *ti = obj;
	int i = -123;
	Uint u = 123;
	float flt = 1.234f;
	double dbl = 2.345;
	long l = -123456;
	Ulong ul = 123456;
	Uint8 u8 = 255;
	Sint8 s8 = -100;
	Uint16 u16 = 1616;
	Sint16 s16 = -1616;
	Uint32 u32 = 323232;
	Sint32 s32 = -323232;
	AG_FmtString *fs;
	M_Vector2 v2 = M_VECTOR2(2.1, M_PI);
	M_Vector3 v3 = M_VECTOR3(3.1, 3.2, M_E);

	Strlcpy(someString, "Some string", sizeof(someString));

	TestMsgS(ti, "AG_Printf() test:");
	TestMsgS(ti, AG_Printf("\tSome string: \"%s\", \"%10s\"", someString, someString));
	TestMsgS(ti, AG_Printf("\tInt: [%d] [%8d] [%08d]", i, i, i));
	TestMsgS(ti, AG_Printf("\tUint: [%u] [%8u] [%08u]", u, u, u));
	TestMsgS(ti, AG_Printf("\tLong: [%ld] [%8ld] [%08ld]", l, l, l));
	TestMsgS(ti, AG_Printf("\tUlong: [%lu] [%8lu] [%08lu]", ul, ul, ul));
	TestMsgS(ti, AG_Printf("\tDbl: [%f] [%.0f] [%.1f] [%.2f] [%.08f]", dbl, dbl, dbl, dbl, dbl));
	TestMsgS(ti, AG_Printf("\tInt=%d Uint=%u Dbl=%f Long=%ld Ulong=%lu", i, u, dbl, l, ul));
	
	TestMsgS(ti, "AG_Printf() extended specifiers:");
	TestMsgS(ti, AG_Printf("\tu8=%[u8], s8=%[s8]", &u8, &s8));
	TestMsgS(ti, AG_Printf("\tu16=%[u16], s16=%[s16]", &u16, &s16));
	TestMsgS(ti, AG_Printf("\tu32=%[u32], s32=%[s32]", &u32, &s32));
	TestMsgS(ti, AG_Printf("\tv2=%[V2], v3=%[V3]", &v2, &v3));

	TestMsgS(ti, "AG_PrintfP() test:");
	fs = AG_PrintfP("\tString: \"%s\"", someString);
	AG_ProcessFmtString(fs, buf, sizeof(buf));
	TestMsgS(ti, buf);
	fs = AG_PrintfP("\tNatural integers: %d, %u", &i, &u);
	AG_ProcessFmtString(fs, buf, sizeof(buf));
	TestMsgS(ti, buf);
	fs = AG_PrintfP("\tFixed integers: %[u8],%[s8],%[u16],%[s16],"
	                "%[u32],%[s32]", &u8, &s8, &u16, &s16, &u32, &s32);
	AG_ProcessFmtString(fs, buf, sizeof(buf));
	TestMsgS(ti, buf);
	fs = AG_PrintfP("\tFloats: %f, %lf", &flt, &dbl);
	AG_ProcessFmtString(fs, buf, sizeof(buf));
	TestMsgS(ti, buf);
	fs = AG_PrintfP("\tVectors: %[V2], %[V3]", &v2, &v3);
	AG_ProcessFmtString(fs, buf, sizeof(buf));
	TestMsgS(ti, buf);

	return (0);
}
Beispiel #16
0
void
rechist(void)
{
    Char    buf[BUFSIZ], hbuf[BUFSIZ], *hfile;
    int     fd, ftmp, oldidfds;
    struct  varent *shist;

    if (!fast) {
	/*
	 * If $savehist is just set, we use the value of $history
	 * else we use the value in $savehist
	 */
	if ((shist = adrof(STRsavehist)) != NULL) {
	    if (shist->vec[0][0] != '\0')
		(void) Strlcpy(hbuf, shist->vec[0], sizeof hbuf/sizeof(Char));
	    else if ((shist = adrof(STRhistory)) && shist->vec[0][0] != '\0')
		(void) Strlcpy(hbuf, shist->vec[0], sizeof hbuf/sizeof(Char));
	    else
		return;
	}
	else
	    return;

	if ((hfile = value(STRhistfile)) == STRNULL) {
	    Strlcpy(buf, value(STRhome), sizeof buf/sizeof(Char));
	    hfile = buf;
	    (void) Strlcat(buf, STRsldthist, sizeof buf/sizeof(Char));
	}

	if ((fd = open(short2str(hfile), O_WRONLY | O_CREAT | O_TRUNC,
	    0600)) == -1)
	    return;

	oldidfds = didfds;
	didfds = 0;
	ftmp = SHOUT;
	SHOUT = fd;
	dumphist[2] = hbuf;
	dohist(dumphist, NULL);
	SHOUT = ftmp;
	(void) close(fd);
	didfds = oldidfds;
    }
}
Beispiel #17
0
    virtual FILE* openFile(
        const char* path,
        int mode)
    {
        AutoMutex autoMutex(_mutex);

        if (mode != 'r' && mode != 'w' && mode != 'a')
            return NULL;

        // Send request header:

        ExecutorRequestHeader header;
        header.code = EXECUTOR_OPEN_FILE_MESSAGE;

        if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header))
            return NULL;

        // Send request body.

        ExecutorOpenFileRequest request;
        memset(&request, 0, sizeof(request));
        Strlcpy(request.path, path, EXECUTOR_BUFFER_SIZE);
        request.mode = mode;

        if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request))
            return NULL;

        // Receive the response

        ExecutorOpenFileResponse response;

        if (RecvBlock(_sock, &response, sizeof(response)) != sizeof(response))
            return NULL;

        // Receive descriptor (if response successful).

        if (response.status == 0)
        {
            int fds[1];

            if (RecvDescriptorArray(_sock, fds, 1) != 0)
                return NULL;

            if (fds[0] == -1)
                return NULL;
            else
            {
                if (mode == 'r')
                    return fdopen(fds[0], "rb");
                else
                    return fdopen(fds[0], "wb");
            }
        }

        return NULL;
    }
Beispiel #18
0
DirEnt* Dir_Read(Dir* self)
{
    struct dirent* p = readdir(self->dir);
    if (!p)
        return NULL;

    Strlcpy(self->ent.name, p->d_name, sizeof(self->ent.name));

    return &self->ent;
}
Beispiel #19
0
static void
SelectedFace(AG_Event *event)
{
	AG_FontSelector *fs = AG_PTR(1);
	AG_TlistItem *it = AG_PTR(2);

	Strlcpy(fs->curFace, it->text, sizeof(fs->curFace));
	UpdateFontSelection(fs);
	UpdatePreview(fs);
}
Internal_DirEnt* Internal_Dir_Read(_In_ Internal_Dir* self, _In_opt_z_ TChar *fileEndsWith)
{
    for(;;)
    {
#if defined(_MSC_VER)

        if (!self->firstTime)
        {
            if (_wfindnext(self->handle, &self->fileinfo) != 0)
                return NULL;
        }
        self->firstTime = 0;
        
        if( StringEndsWith(self->fileinfo.name, fileEndsWith) != 0 )
            continue;
        Wcslcpy(self->ent.name, self->fileinfo.name, PAL_MAX_PATH_SIZE);
        if( self->fileinfo.attrib & _A_SUBDIR )
            self->ent.isDir = 1;
        else
            self->ent.isDir = 0;
        
        return &self->ent;

#else
        struct dirent* p = readdir(self->dir);
        struct stat st;
        TChar filespec[PAL_MAX_PATH_SIZE];
        if (!p)
            return NULL;

        if( StringEndsWith(p->d_name, fileEndsWith) != 0 )
            continue;        

        Strlcpy(self->ent.name, p->d_name, PAL_MAX_PATH_SIZE);
        // Logic to detect Dir may not work on non-linux, non-windows platforms, in which case
        // We would need to use Isdir method.
        //self->ent.isDir = Isdir(self->ent.name);  
        if( Tcslcpy(filespec, self->dirName, PAL_MAX_PATH_SIZE) >= PAL_MAX_PATH_SIZE)
            return NULL;

        if( Tcslcat(filespec, "/", PAL_MAX_PATH_SIZE) >= PAL_MAX_PATH_SIZE)
            return NULL;

        if( Tcslcat(filespec, self->ent.name, PAL_MAX_PATH_SIZE) >= PAL_MAX_PATH_SIZE)
            return NULL;

        if (stat(filespec, &st) != 0)      
            return NULL;
        // self->ent.isDir = (p->d_type & DT_DIR) ? 1 : 0;
        self->ent.isDir = S_ISDIR(st.st_mode);
        return &self->ent;

#endif       
    }
}
Beispiel #21
0
/* Specify static text (C string). */
void
VG_TextString(VG_Text *vt, const char *s)
{
	VG_Lock(VGNODE(vt)->vg);
	if (s != NULL) {
		Strlcpy(vt->text, s, sizeof(vt->text));
	} else {
		vt->text[0] = '\0';
	}
	VG_Unlock(VGNODE(vt)->vg);
}
Beispiel #22
0
DirEnt* Dir_Read(Dir* dir)
{
    if (!dir->firstTime)
    {
        if (_findnext(dir->handle, &dir->fileinfo) != 0)
            return NULL;
    }

    Strlcpy(dir->ent.name, dir->fileinfo.name, PAL_MAX_PATH_SIZE);
    dir->firstTime = 0;
    return &dir->ent;
}
Beispiel #23
0
static void
SetDirectoryAndFile(AG_FileSelector *fs, const char *pPath)
{
    char path[AG_FILENAME_MAX], *file;

    Strlcpy(path, pPath, sizeof(path));
    if ((file = strrchr(path, AG_PATHSEPCHAR)) != NULL) {
        AG_FileDlgSetFilenameS(fs->filedlg, file);
        *file = '\0';
        AG_FileDlgSetDirectoryS(fs->filedlg, path);
    }
}
Beispiel #24
0
/* Copy the full pathname of a data file to a sized buffer. */
int
AG_ConfigFile(const char *path_key, const char *name, const char *ext,
    char *path, size_t path_len)
{
	char file[AG_PATHNAME_MAX];
	char *dir, *pathp = path;
	int rv;

	AG_GetString(agConfig, path_key, path, path_len);

	for (dir = Strsep(&pathp, AG_PATHSEPMULTI);
	     dir != NULL;
	     dir = Strsep(&pathp, AG_PATHSEPMULTI)) {
		Strlcpy(file, dir, sizeof(file));

		if (name[0] != AG_PATHSEPCHAR) {
			Strlcat(file, AG_PATHSEP, sizeof(file));
		}
		Strlcat(file, name, sizeof(file));
		if (ext != NULL) {
			Strlcat(file, ".", sizeof(file));
			Strlcat(file, ext, sizeof(file));
		}
		if ((rv = AG_FileExists(file)) == 1) {
			if (Strlcpy(path, file, path_len) >= path_len) {
				AG_SetError(_("The search path is too big."));
				return (-1);
			}
			return (0);
		} else if (rv == -1) {
			AG_SetError("%s: %s", file, AG_GetError());
			return (-1);
		}
	}
	AG_GetString(agConfig, path_key, path, path_len);
	AG_SetError(_("Cannot find %s.%s (in <%s>:%s)."), name,
	    (ext != NULL) ? ext : "", path_key, path);
	return (-1);
}
Beispiel #25
0
Datei: xbox.c Projekt: adsr/agar
char*
AG_XBOX_GetDeviceFromLogicalDrive(const char *drive)
{
	HANDLE h;
	ANSI_STRING szDevice;
	ANSI_STRING szDrive;
	OBJECT_ATTRIBUTES attr;
	ULONG size;
	char devBuf[256];
	char driveL[3];
	char driveP[7];

	if(!drive || strlen(drive) < 2 ||
		!isalpha(drive[0]) || drive[1] != ':') {
		return NULL;
	}

	Strlcpy(driveL, drive, sizeof(driveL));
	Snprintf(driveP, sizeof(driveP), "\\??\\%s", driveL);
	RtlInitAnsiString(&szDrive, driveP);

	szDevice.Buffer = devBuf;
	szDevice.Length = 0xf;
	szDevice.MaximumLength = 256;

	InitializeObjectAttributes(&attr, &szDrive, OBJ_CASE_INSENSITIVE, NULL);

	if(SUCCEEDED(NtOpenSymbolicLinkObject(&h, &attr))) {
		if(SUCCEEDED(NtQuerySymbolicLinkObject(h, &szDevice, &size))) {
			Strlcpy(devBuf, szDevice.Buffer, size + 1);
			CloseHandle(h);
			return TryStrdup(devBuf);
		}
		CloseHandle(h);
	}

	return NULL;
}
Beispiel #26
0
void
AG_FileSelectorSetDirectory(AG_FileSelector *fs, const char *path)
{
    char dir[AG_PATHNAME_MAX];

    Strlcpy(dir, path, sizeof(dir));
    if (dir[0] != '\0' && dir[strlen(dir)-1] != AG_PATHSEPCHAR) {
        dir[strlen(dir)-1] = AG_PATHSEPCHAR;
    }
    AG_ObjectLock(fs->filedlg);
    SetDirectory(fs, dir);
    AG_TextboxSetString(fs->tbox, dir);
    AG_ObjectUnlock(fs->filedlg);
}
Beispiel #27
0
    virtual int authenticateLocal(
        const char* challengeFilePath,
        const char* response)
    {
        AutoMutex autoMutex(_mutex);

        // Send request header:

        ExecutorRequestHeader header;
        header.code = EXECUTOR_AUTHENTICATE_LOCAL_MESSAGE;

        if (SendBlock(_sock, &header, sizeof(header)) != sizeof(header))
            return -1;

        // Send request body.

        ExecutorAuthenticateLocalRequest request;
        memset(&request, 0, sizeof(request));
        Strlcpy(request.challenge, challengeFilePath, EXECUTOR_BUFFER_SIZE);
        Strlcpy(request.response, response, EXECUTOR_BUFFER_SIZE);

        if (SendBlock(_sock, &request, sizeof(request)) != sizeof(request))
            return -1;

        // Receive the response

        ExecutorAuthenticateLocalResponse response_;

        if (RecvBlock(_sock, &response_, sizeof(response_)) !=
                sizeof(response_))
        {
            return -1;
        }

        return response_.status;
    }
Beispiel #28
0
static void
SelectFont(AG_Event *event)
{
	VG_Text *vt = AG_PTR(1);
	AG_Window *win = AG_PTR(2);
	AG_FontSelector *fs = AG_PTR(3);

	Strlcpy(vt->fontFace, fs->curFace, sizeof(vt->fontFace));
	vt->fontSize = fs->curSize;
	vt->fontFlags = 0;
	if (fs->curStyle & AG_FONT_BOLD) { vt->fontFlags |= VG_TEXT_BOLD; }
	if (fs->curStyle & AG_FONT_ITALIC) { vt->fontFlags |= VG_TEXT_ITALIC; }

	AG_ObjectDetach(win);
}
Beispiel #29
0
/* Read_Comments()
 *
 * Reads CM comment cards from input file
 */
  gboolean
Read_Comments( void )
{
  char ain[3], line_buf[LINE_LEN];


  /* Look for CM or CE card */
  do
  {
    /* read a line from input file */
    if( Load_Line(line_buf, input_fp) == EOF )
    {
      fprintf( stderr, "xnec2c: Read_Comments():"
          "unexpected EOF (End of File)\n" );
      stop( _("Read_Comments(): Error reading Comments\n"\
            "Unexpected EOF (End of File)"), ERR_OK );
      return( FALSE );
    }

    /* Check that comment line is not short */
    if( strlen(line_buf) < 2 )
    {
      fprintf( stderr, "xnec2c: Read_Comments():"
          "error reading Comments: "
          "Comment mnemonic short or missing\n" );
      stop( _("Read_Comments(): Error reading Comments\n"\
            "Comment mnemonic short or missing"), ERR_OK );
      return( FALSE );
    }

    /* separate card's id mnemonic */
    Strlcpy( ain, line_buf, sizeof(ain) );

    /* Check for incorrect mnemonic */
    if( (strcmp(ain, "CM") != 0) && (strcmp(ain, "CE") != 0) )
    {
      stop( _("Read_Comments():\n"\
            " Error reading input file\n"\
            "Comment mnemonic incorrect"), ERR_OK );
      return( FALSE );
    }
  }
  while( (strcmp(ain, "CE") != 0) );

  return( TRUE );
} /* Read_Comments() */
Beispiel #30
0
int
AG_ConfigInit(AG_Config *cfg, Uint flags)
{
	char path[AG_PATHNAME_MAX], *s;
	AG_User *sysUser;

	AG_ObjectInit(cfg, &agConfigClass);
	AG_ObjectSetName(cfg, "config");
	OBJECT(cfg)->save_pfx = NULL;

	AG_SetInt(cfg, "initial-run", 1);
	AG_SetInt(cfg, "no-confirm-quit", 0);

	if (agProgName != NULL &&
	    (sysUser = AG_GetRealUser()) != NULL) {
		AG_SetString(cfg, "home", sysUser->home);
		AG_SetString(cfg, "tmp-path", sysUser->tmp);

		Strlcpy(path, sysUser->home, sizeof(path));
		Strlcat(path, AG_PATHSEP, sizeof(path));
		Strlcat(path, ".", sizeof(path));
		Strlcat(path, agProgName, sizeof(path));
		AG_SetString(cfg, "save-path", path);

		if (strcmp(DATADIR, "NONE") != 0) {
			AG_PrtString(cfg, "load-path", "%s%s%s",
			    path, AG_PATHSEPMULTI, DATADIR);
		} else {
			AG_SetString(cfg, "load-path", path);
		}
		AG_UserFree(sysUser);
	} else {
		AG_SetString(cfg, "home", "");
		s = (strcmp(DATADIR,"NONE") != 0) ? DATADIR : ".";
		AG_SetString(cfg, "load-path", s);
		AG_SetString(cfg, "save-path", s);
		AG_SetString(cfg, "tmp-path", "tmp");
	}

	if ((flags & AG_CREATE_DATADIR) &&
	    AG_CreateDataDir() == -1) {
		return (-1);
	}
	return (0);
}