Example #1
0
// Actual evaluation of surface matrix form (calculates integral)
scalar FeProblem::eval_form(WeakForm::MatrixFormSurf *mfs, Tuple<Solution *> u_ext, PrecalcShapeset *fu, PrecalcShapeset *fv, RefMap *ru, RefMap *rv, EdgePos* ep)
{
  // eval the form
  Quad2D* quad = fu->get_quad_2d();
  int eo = quad->get_edge_points(ep->edge);
  double3* pt = quad->get_points(eo);
  int np = quad->get_num_points(eo);

  // init geometry and jacobian*weights
  if (cache_e[eo] == NULL)
  {
    cache_e[eo] = init_geom_surf(ru, ep, eo);
    double3* tan = ru->get_tangent(ep->edge);
    cache_jwt[eo] = new double[np];
    for(int i = 0; i < np; i++)
      cache_jwt[eo][i] = pt[i][2] * tan[i][2];
  }
  Geom<double>* e = cache_e[eo];
  double* jwt = cache_jwt[eo];

  // function values and values of external functions
  AUTOLA_OR(Func<scalar>*, prev, wf->neq);
  for (int i = 0; i < wf->neq; i++) prev[i]  = init_fn(u_ext[i], rv, eo);
  Func<double>* u = get_fn(fu, ru, eo);
  Func<double>* v = get_fn(fv, rv, eo);
  ExtData<scalar>* ext = init_ext_fns(mfs->ext, rv, eo);

  scalar res = mfs->fn(np, jwt, prev, u, v, e, ext);

  for (int i = 0; i < wf->neq; i++) {  prev[i]->free_fn(); delete prev[i]; }
  ext->free(); delete ext;
  return 0.5 * res;
}
void *thread_test_fun(void *arg) {
    void        *buf;
    _bcc_status  cc;
    int          count_read;
    int          count_xferred;
    int          ferr;
    int          inx;
    SB_Tag_Type  tag1;
    short        tfilenum;
    int          timeout = -1;

    arg = arg; // touch
    ferr = BFILE_OPEN_((char *) sname, 4, &filenum,
                       0, 0, 1,  // nowait
                       0,
                       0x4400,   // nowait-open/tsc
                       0, 0, NULL);
    TEST_CHK_FEOK(ferr);
    tfilenum = get_fn(filenum);
    cc = BAWAITIOXTS(&tfilenum,
                     &buf,
                     &count_xferred,
                     &tag1,
                     timeout,
                     NULL);
    TEST_CHK_CCEQ(cc);
    assert(tag1 == -30);

    for (inx = 0; inx < loop; inx++) {
        sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                my_name, inx);
        cc = BWRITEREADX(filenum,
                         send_buffer,
                         (int) (strlen(send_buffer) + 1), // cast
                         BUFSIZ,
                         &count_read,
                         0);
        TEST_CHK_CCEQ(cc);
        tfilenum = get_fn(filenum);
        cc = BAWAITIOXTS(&tfilenum,
                         &buf,
                         &count_xferred,
                         &tag1,
                         timeout,
                         NULL);
        TEST_CHK_CCEQ(cc);
        printf("%s\n", send_buffer);
    }

    // let thread-exit close
    if (!thread) {
        ferr = BFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }

    return NULL;
}
Example #3
0
static void get_fn_pointers(SOCKET s)
{
    GUID acceptex_guid = WSAID_ACCEPTEX;
    GUID acceptexsockaddrs_guid = WSAID_GETACCEPTEXSOCKADDRS;
    GUID transmitfile_guid = WSAID_TRANSMITFILE;

    get_fn(s, &acceptex_guid, (FARPROC*)&acceptex_fn);
    get_fn(s, &acceptexsockaddrs_guid, (FARPROC*)&acceptexsockaddrs_fn);
    get_fn(s, &transmitfile_guid, (FARPROC*)&transmitfile_fn);
    initialised = TRUE;
}
Example #4
0
// Actual evaluation of volume matrix form (calculates integral)
scalar FeProblem::eval_form(WeakForm::MatrixFormVol *mfv, Tuple<Solution *> u_ext, PrecalcShapeset *fu, PrecalcShapeset *fv, RefMap *ru, RefMap *rv)
{
  // determine the integration order
  int inc = (fu->get_num_components() == 2) ? 1 : 0;
  AUTOLA_OR(Func<Ord>*, oi, wf->neq);
  for (int i = 0; i < wf->neq; i++) oi[i] = init_fn_ord(u_ext[i]->get_fn_order() + inc);
  Func<Ord>* ou = init_fn_ord(fu->get_fn_order() + inc);
  Func<Ord>* ov = init_fn_ord(fv->get_fn_order() + inc);
  ExtData<Ord>* fake_ext = init_ext_fns_ord(mfv->ext);

  double fake_wt = 1.0;
  Geom<Ord>* fake_e = init_geom_ord();
  Ord o = mfv->ord(1, &fake_wt, oi, ou, ov, fake_e, fake_ext);
  int order = ru->get_inv_ref_order();
  order += o.get_order();
  limit_order_nowarn(order);

  for (int i = 0; i < wf->neq; i++) {  oi[i]->free_ord(); delete oi[i]; }
  ou->free_ord(); delete ou;
  ov->free_ord(); delete ov;
  delete fake_e;
  fake_ext->free_ord(); delete fake_ext;

  // eval the form
  Quad2D* quad = fu->get_quad_2d();
  double3* pt = quad->get_points(order);
  int np = quad->get_num_points(order);

  // init geometry and jacobian*weights
  if (cache_e[order] == NULL)
  {
    cache_e[order] = init_geom_vol(ru, order);
    double* jac = ru->get_jacobian(order);
    cache_jwt[order] = new double[np];
    for(int i = 0; i < np; i++)
      cache_jwt[order][i] = pt[i][2] * jac[i];
  }
  Geom<double>* e = cache_e[order];
  double* jwt = cache_jwt[order];

  // function values and values of external functions
  AUTOLA_OR(Func<scalar>*, prev, wf->neq);
  for (int i = 0; i < wf->neq; i++) prev[i]  = init_fn(u_ext[i], rv, order);
  Func<double>* u = get_fn(fu, ru, order);
  Func<double>* v = get_fn(fv, rv, order);
  ExtData<scalar>* ext = init_ext_fns(mfv->ext, rv, order);

  scalar res = mfv->fn(np, jwt, prev, u, v, e, ext);

  for (int i = 0; i < wf->neq; i++) {  prev[i]->free_fn(); delete prev[i]; }
  ext->free(); delete ext;
  return res;
}
Example #5
0
static HANDLE alloc_fd(int job_id)
{
	HANDLE result = temp_files[job_id];

	if (!result)
	{
		char temp_path[MAX_PATH];
		DWORD access, sharemode, disp, flags;

		get_fn(job_id, temp_path);

		access		= GENERIC_WRITE | GENERIC_READ;
		sharemode = FILE_SHARE_WRITE;
		disp			= CREATE_ALWAYS;
		flags			= FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE;

		result = CreateFileA(temp_path, access, sharemode, NULL, disp, flags, NULL);

		if (INVALID_HANDLE_VALUE == result)
		{
			fprintf(stderr, "failed to create temporary file %s\n", temp_path);
			return INVALID_HANDLE_VALUE;
		}

		SetHandleInformation(result, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);

		temp_files[job_id] = result;
	}

	return result;
}
Example #6
0
void
ltspfs_link (int sockfd, XDR *in)
{
  char from[PATH_MAX];
  char to[PATH_MAX];

  if (get_fn(sockfd, in, from)) {		/* Get the source link */
    eacces(sockfd);
    return;
  }
  if (get_fn(sockfd, in, to)) {		/* Get the destination link*/
    eacces(sockfd);
    return;
  }

  status_return (sockfd, link (from, to));
}
Example #7
0
void
ltspfs_rmdir (int sockfd, XDR *in)
{
  char path[PATH_MAX];

  if (get_fn(sockfd, in, path)) {		/* Get the path */
    eacces(sockfd);
    return;
  }

  status_return (sockfd, rmdir (path));
}
Example #8
0
void
ltspfs_readdir (int sockfd, XDR *in)
{
  XDR  out;
  char path[PATH_MAX];
  char output[LTSP_MAXBUF];
  DIR  *dp;
  char *nameptr;
  struct dirent *de;
  int  i;

  if (get_fn(sockfd, in, path)) {		/* Get the dir name */ 
    eacces(sockfd);
    return;
  }

  dp = opendir (path);

  if (dp == NULL) {
    status_return(sockfd, FAIL);		/* opendir failed */
    return;
  }

  while ((de = readdir (dp)) != NULL) {
    xdrmem_create(&out, output, LTSP_MAXBUF, XDR_ENCODE);
    i = 0;
    xdr_int(&out, &i);	 			/* First, the dummy length */
    i = LTSP_STATUS_CONT;
    xdr_int(&out, &i);				/* Then the 2 status return */
    xdr_u_longlong_t(&out, &(de->d_ino));	/* Inode */
    xdr_u_char(&out, &(de->d_type));		/* type */
    nameptr = de->d_name;
    xdr_string(&out, &nameptr, PATH_MAX);	/* filename */
    i = xdr_getpos(&out);			/* Get our position */
    xdr_setpos(&out, 0);			/* Rewind to the beginning */
    xdr_int(&out, &i);				/* Rewrite with proper length */
    xdr_destroy(&out);

    if (debug)
      info("returning %s", de->d_name);

    writen(sockfd, output, i);
  }

  closedir (dp);

  status_return(sockfd, OK);
}
Example #9
0
void
ltspfs_getattr (int sockfd, XDR *in)
{
  XDR         out;
  char        path[PATH_MAX];
  char 	      output[LTSP_MAXBUF];
  int         i;
  struct stat stbuf;

  if (get_fn(sockfd, in, path)) {
    if (debug)
      info ("get_fn failed\n");
    eacces(sockfd);
    return;
  }

  if (lstat (path, &stbuf) == -1) {
    status_return(sockfd, FAIL);
    return;
  }

  xdrmem_create(&out, output, LTSP_MAXBUF, XDR_ENCODE);
  i = 0;
  xdr_int(&out, &i);	 			/* First, the dummy length */
  xdr_int(&out, &i);				/* Then the 0 status return */
  xdr_u_longlong_t(&out, &(stbuf.st_dev));	/* device */
  xdr_u_longlong_t(&out, &(stbuf.st_ino));	/* inode */
  xdr_u_int(&out, &(stbuf.st_mode));		/* protection */
  xdr_u_int(&out, &(stbuf.st_nlink));		/* number of hard links */
  xdr_u_int(&out, &(stbuf.st_uid));		/* user ID of owner */
  xdr_u_int(&out, &(stbuf.st_gid));		/* group ID of owner */
  xdr_u_longlong_t(&out, &(stbuf.st_rdev));	/* device type */
  xdr_longlong_t(&out, &(stbuf.st_size));	/* total size, in bytes */
  xdr_long(&out, &(stbuf.st_blksize));		/* blocksize for fs I/O */
  xdr_longlong_t(&out, &(stbuf.st_blocks));	/* number of blocks allocated */
  xdr_long(&out, &(stbuf.st_atime));		/* time of last access */
  xdr_long(&out, &(stbuf.st_mtime));		/* time of last modification */
  xdr_long(&out, &(stbuf.st_ctime));		/* time of last status change */
  i = xdr_getpos(&out);				/* Get our position */
  xdr_setpos(&out, 0);				/* Rewind to the beginning */
  xdr_int(&out, &i);				/* Rewrite with proper length */
  xdr_destroy(&out);

  if (debug)
    info("returning OK");

  writen(sockfd, output, i);
}
Example #10
0
bool schedule_function(std::function<void(void)> fn)
{
    scheduled_fn_t* item = get_fn();
    if (!item) {
        return false;
    }
    item->mFunc = fn;
    item->mNext = NULL;
    if (!sFirst) {
        sFirst = item;
    }
    else {
        sLast->mNext = item;
    }
    sLast = item;
    return true;
}
Example #11
0
void
ltspfs_chmod (int sockfd, XDR *in)
{
  char   path[PATH_MAX];
  mode_t mode;

  if (!xdr_u_int(in, &mode)) {			/* Get the mode */
    eacces(sockfd);
    return;
  }

  if (get_fn(sockfd, in, path)) {		/* Get the path */
    eacces(sockfd);
    return;
  }

  status_return (sockfd, chmod (path, mode));
}
Example #12
0
void
ltspfs_truncate (int sockfd, XDR *in)
{
  char  path[PATH_MAX];
  off_t offset;

  if (!xdr_longlong_t(in, &offset)) {		/* Get the mode */
    eacces(sockfd);
    return;
  }

  if (get_fn(sockfd, in, path)) {		/* Get the path */
    eacces(sockfd);
    return;
  }

  status_return (sockfd, truncate (path, offset));
}
Example #13
0
void
ltspfs_statfs (int sockfd, XDR *in)
{
  XDR out;
  char path[PATH_MAX];
  char output[LTSP_MAXBUF];
  struct statfs stbuf;
  int i;

  if (get_fn(sockfd, in, path)) {		/* Get the path */
    eacces(sockfd);
    return;
  }


  if (statfs (path, &stbuf) == -1) {
    status_return(sockfd, FAIL);
    return;
  }

  xdrmem_create(&out, output, LTSP_MAXBUF, XDR_ENCODE);
  i = 0;
  xdr_int(&out, &i);				/* dummy length */
  i = LTSP_STATUS_OK;				/* OK status */
  xdr_int(&out, &i);
  xdr_int(&out, &stbuf.f_type);       		/* type of fs */
  xdr_int(&out, &stbuf.f_bsize); 		/* optimal transfer block sz */
  xdr_u_longlong_t(&out, &stbuf.f_blocks);	/* total data blocks in fs */
  xdr_u_longlong_t(&out, &stbuf.f_bfree);	/* free blks in fs */
  xdr_u_longlong_t(&out, &stbuf.f_bavail);      /* free blks avail to non-su */
  xdr_u_longlong_t(&out, &stbuf.f_files);       /* total file nodes in fs */
  xdr_u_longlong_t(&out, &stbuf.f_ffree);	/* free file nodes in fs */
  xdr_int(&out, &stbuf.f_namelen); 		/* max length of filenames */
  i = xdr_getpos(&out);	 			/* Get current position */
  xdr_setpos(&out, 0);	 			/* rewind to the beginning */
  xdr_int(&out, &i);				/* re-write proper length */
  xdr_destroy(&out);				/* Clean up the XDR structs */

  if (debug)
    info("returning OK");

  writen(sockfd, output, i);
}
Example #14
0
void
ltspfs_readlink (int sockfd, XDR *in)
{
  XDR  out;
  char path[PATH_MAX];
  char buf[PATH_MAX];				/* linkname */
  char output[LTSP_MAXBUF];
  char *bufptr = buf;
  int  i;

  /* readlink doesn't terminate with a null */
  memset (buf, 0, PATH_MAX);

  if (get_fn(sockfd, in, path)) {		/* Get the link source */
    eacces(sockfd);
    return;
  }

  if (readlink (path, buf, PATH_MAX) == -1) {
    status_return(sockfd, FAIL);
    return;
  }

  if (!strncmp(buf, mountpoint, strlen(mountpoint)))	/* adjust link target */
    bufptr += strlen(mountpoint);

  xdrmem_create(&out, output, LTSP_MAXBUF, XDR_ENCODE);
  i = 0;
  xdr_int(&out, &i);	 			/* First, the dummy length */
  xdr_int(&out, &i);				/* Then the 0 status return */
  xdr_string(&out, &bufptr, PATH_MAX);		/* Link target */
  i = xdr_getpos(&out);				/* Get our position */
  xdr_setpos(&out, 0);				/* Rewind to the beginning */
  xdr_int(&out, &i);				/* Rewrite with proper length */
  xdr_destroy(&out);

  if (debug)
    info("returning ok", output);

  writen(sockfd, output, i);
}
Example #15
0
void
ltspfs_open (int sockfd, XDR *in)
{
  char path[PATH_MAX];
  int  result;
  int  flags;

  if (!xdr_int(in, &flags)) {			/* Get the flags */
    eacces(sockfd);
    return;
  }

  if (get_fn(sockfd, in, path)) {		/* Get the path */
    eacces(sockfd);
    return;
  }

  /*
   * If we're a read-only filesystem, and we've been asked to open 
   * O_WRONLY or O_RDWR, then return EACCES
   */

  if (readonly)
    if ( (flags & O_WRONLY) || (flags & O_RDWR) ) {
      eacces(sockfd);
      return;
    }

  /*
   * Otherwise, check the permissions with a test open, and return the 
   * results if an error occurred.
   */

  result = open (path, flags);

  status_return (sockfd, result);

  if (result != -1)
    close (result);
}
Example #16
0
void
ltspfs_utime (int sockfd, XDR *in)
{
  char path[PATH_MAX];
  struct utimbuf timbuf;

  if (!xdr_long(in, &timbuf.actime)) {		/* Get the actime */
    eacces(sockfd);
    return;
  }

  if (!xdr_long(in, &timbuf.modtime)) {		/* Get the modtime */
    eacces(sockfd);
    return;
  }

  if (get_fn(sockfd, in, path)) {		/* Get the path */
    eacces(sockfd);
    return;
  }

  status_return (sockfd, utime (path, &timbuf));
}
Example #17
0
static int dlorean_open(const char *path, struct fuse_file_info *fi)
{
	int n;
	char *path_t;
	
	samefs(real_path, mount_point_path);
	/* The line below doesn't work :(. Perhaps i should check only "readonly"
	* flag in an open operation
	*/
	//if ((fi->flags == O_WRONLY) || (fi->flags == O_RDWR))
	/*
	* if ((fi->flags > O_RDONLY))
	*      save_a_copy(path);
	*/
	/* When i open some files (if they already exist) the flags
	* are 32768 (with "more" for example) or > 32768.
	* Is read only 0 only?
	*/
	
	int time = in_the_past(fuse_get_context()->pid);
	if (time > 0)
		path_t=get_fn(path, time);
	else {
		check_and_save(path);
		path_t = strcatloc(real_path, path);
	};
	
	n = open (path_t, fi->flags);
	free(path_t);
	if (n == -1) {
		perror("open");
		return -EACCES;
	} 
	fi->fh = n;
	
	return 0;
}
Example #18
0
static int dlorean_getattr(const char *path, struct stat *stbuf)
{
	char *path_t;
	int res = 0;
	int time;
	
	if (!fc_getattr(path)){
		printf("devuelvo 0!..\n");
		res = lstat("/dev/null",stbuf);
		return 0;
	};
	
	//  **** PARA NO PERMITIR EL INGRESO AL DIRECTORIO de versiones !!**
	if (!strncmp(versions_place,path+1,strlen(versions_place)))
		    return -2;
	
	if (fuse_get_context()->pid < 1) 
		    return -2;

	if ((time=in_the_past(fuse_get_context()->pid)) > 0) 
		path_t=get_fn(path, time);
	else
		path_t = strcatloc(real_path, path);
	
	// el siguiente memset.. puede ser reemplazado por stbuf[..]=0?
	memset(stbuf, 0, sizeof(struct stat));
	
	// utilizo lstat para poder obtener tambien el stat de symbolic links
	res = lstat(path_t, stbuf);
	
	free(path_t);
	
	// if res<0 then hubo un error con stat. Devuelvo -2 (no such file or dir)
	if (res < 0)
		res = -2;
	return res;
}
Example #19
0
void
ltspfs_mknod (int sockfd, XDR *in)
{
  char   path[PATH_MAX];
  mode_t mode;
  dev_t  rdev;

  if (!xdr_u_int(in, &mode)) {			/* Get the mode */
    eacces(sockfd);
    return;
  }
  
  if (!xdr_u_longlong_t(in, &rdev)) {		/* Get the device type */
    eacces(sockfd);
    return;
  }

  if (get_fn(sockfd, in, path)) {		/* Get the dir name */
    eacces(sockfd);
    return;
  }

  status_return (sockfd, mknod (path, mode, rdev));
}
Example #20
0
void
ltspfs_chown (int sockfd, XDR *in)
{
  char  path[PATH_MAX];
  uid_t uid;
  gid_t gid;

  if (!xdr_u_int(in, &uid)) {			/* Get the mode */
    eacces(sockfd);
    return;
  }

  if (!xdr_u_int(in, &gid)) {			/* Get the mode */
    eacces(sockfd);
    return;
  }

  if (get_fn(sockfd, in, path)) {		/* Get the path */
    eacces(sockfd);
    return;
  }

  status_return (sockfd, chown (path, uid, gid));
}
Example #21
0
static long MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_CREATE:
        hDC = GetDC(hWnd);
        bits_per_pixel = GetDeviceCaps(hDC, BITSPIXEL);
        planes = GetDeviceCaps(hDC, PLANES);
        break;
    
    case WM_SIZE:
        WINAPISendMessage(hWnd, WM_COMMAND, IDM_DEMO_STOP, 0);
        if (hBitmap != NULL)
        {
            DeleteDC(hMemDC);
            DeleteObject(hBitmap);
        }
        hMemDC = CreateCompatibleDC(hDC);
        hBitmap = CreateCompatibleBitmap(hDC, LOWORD(lParam), HIWORD(lParam));
        xMax = LOWORD(lParam);
        yMax = HIWORD(lParam);
        SelectObject(hMemDC, hBitmap);
        clear_window(hWnd);
        UpdateWindow(hWnd);
        return DefWindowProc(hWnd, msg, wParam, lParam);

    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        RECT        rect;

        BeginPaint(hWnd, &ps);

        memcpy(&rect, &ps.rcPaint, sizeof(RECT));
        BitBlt(ps.hdc, rect.left, rect.top, rect.right - rect.left,
               rect.bottom - rect.top, hMemDC, rect.left, rect.top, SRCCOPY);

        EndPaint(hWnd, &ps);
        break;
    }

    case WM_COMMAND:
        switch(wParam)
        {
        case IDM_FILE_EXIT:
            PostMessage(hWnd, WM_CLOSE, 0, 0L);
            break;

        case IDM_FILE_CLEAR:
            clear_window(hWnd);
            UpdateWindow(hWnd);
            break;

        case IDM_FILE_PERIODIC:
            WINAPISendMessage(hWnd, WM_COMMAND, IDM_DEMO_STOP, 0);
            if (PainterNeeded)
                CheckMenuItem(hFilePopup, IDM_FILE_PERIODIC, MF_BYCOMMAND | MF_UNCHECKED);
            else
                CheckMenuItem(hFilePopup, IDM_FILE_PERIODIC, MF_BYCOMMAND | MF_CHECKED);
            PainterNeeded = !PainterNeeded;
            break;

        case IDM_DEMO_STOP:
            if (TestSemaphore(&DemoRun))
            {
                Wait(&DemoRun);
                check_item(IDM_DEMO_STOP);
                Wait(&Done);
            }
            break;

        case IDM_DEMO_DIB:
            do_dib();
            break;

        case IDM_DEMO_RANDOM:
        case IDM_DEMO_ARC:
        case IDM_DEMO_CHORD:
        case IDM_DEMO_ELLIPSE:
        case IDM_DEMO_FILLRECT:
        case IDM_DEMO_LINETO:
        case IDM_DEMO_PIE:
        case IDM_DEMO_POLYGON:
        case IDM_DEMO_POLYLINE:
        case IDM_DEMO_RECTANGLE:
        case IDM_DEMO_SETPIXEL:
            if (uLastCommand != wParam)
            {
                VoidFnPtr fn;

                WINAPISendMessage(hWnd, WM_COMMAND, IDM_DEMO_STOP, 0);

                clear_window(hWnd);

                if ((fn = get_fn(wParam)) == NULL)
                    break;
                
                Signal(&DemoRun);
                Fork(2000, fn, 0);
                if (PainterNeeded)
                    Signal(&PainterRequired);
                check_item(wParam);
            }
            break;
        }
        break;
    
    case WM_CLOSE:
        WINAPISendMessage(hWnd, WM_COMMAND, IDM_DEMO_STOP, 0);
        DefWindowProc(hWnd, msg, wParam, lParam);
        DeleteDC(hMemDC);
        DeleteObject(hBitmap);
        ReleaseDC(hWnd, hDC);
        Wait(&Running);
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        return DefWindowProc(hWnd, msg, wParam, lParam);
    
    default:
        return DefWindowProc(hWnd, msg, wParam, lParam);
    }
    return 0;
}
Example #22
0
int main(int argc, char **argv)
{
	int fd;
	char *socket_path = "/var/run/nscd/socket";
	char *config_path = "/etc/nsswitch.conf";
	char *pid_path = 0;
	bool daemonize = false;
	int c;

	init_program_invocation_name(argv[0]);

	while((c = getopt(argc, argv, "c:s:p:d")) != -1) switch(c) {
	case 'c':
		config_path = optarg;
		break;
	case 's':
		socket_path = optarg;
		break;
	case 'p':
		pid_path = optarg;
		break;
	case 'd':
		daemonize = true;
		break;
	default:
		return 1;
	}

	yyin = fopen(config_path, "r");
	if(!yyin) die();

	errno = 0;
	if(yyparse()) {
		if(errno) die();
		return 1;
	}

	link_t *entry_l, *service_l;

	entry_l = list_head(&parsed_output);
	while(entry_l) {
		struct entry *entry = list_ref(entry_l, struct entry, link);
		struct service *service;
		char *buf, *fnname;

		service_l = list_head(&entry->services);
		while(service_l) {
			service = list_ref(service_l, struct service, link);
			if(entry->database == DB_PASSWD) {
				void *dll, *fn;
				struct mod_passwd *mod;
				mod = malloc(sizeof(*mod));
				if(!mod) die();

				dll = get_dll(service->service);
				mod->nss_getpwnam_r = (nss_getpwnam_r)get_fn(dll, "getpwnam", service->service);
				mod->nss_getpwuid_r = (nss_getpwuid_r)get_fn(dll, "getpwuid", service->service);

				memcpy(mod->on_status, service->on_status, sizeof(mod->on_status));

				list_push_back(&passwd_mods, &mod->link);
			} else if(entry->database == DB_GROUP) {
				void *dll, *fn;
				struct mod_group *mod;
				mod = malloc(sizeof(*mod));
				if(!mod) die();

				dll = get_dll(service->service);
				mod->nss_getgrnam_r = (nss_getgrnam_r)get_fn(dll, "getgrnam", service->service);
				mod->nss_getgrgid_r = (nss_getgrgid_r)get_fn(dll, "getgrgid", service->service);
				mod->initgroups_dyn_function = (initgroups_dyn_function)get_fn(dll, "initgroups", service->service);
				dlclose(dll);

				memcpy(mod->on_status, service->on_status, sizeof(mod->on_status));

				list_push_back(&group_mods, &mod->link);
			}
			service_l = list_next(service_l);
			free(service->service);
			free(service);
		}
		entry_l = list_next(entry_l);
		free(entry);
	}

	fd = socket(PF_UNIX, SOCK_STREAM, 0);
	if(fd < 0) die();
	struct sockaddr_un addr = {
		.sun_family = AF_UNIX
	};
	strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path));
	if(bind(fd, (struct sockaddr*)&addr, sizeof addr) < 0) {
		int tmp_fd;
		if(errno != EADDRINUSE)
			die();
		tmp_fd = socket(PF_UNIX, SOCK_STREAM, 0);
		if(tmp_fd < 0) die();
		if(connect(tmp_fd, (struct sockaddr*)&addr, sizeof addr) >= 0) {
			errno = EADDRINUSE;
			die();
		} else if(errno != ECONNREFUSED) die();
		close(tmp_fd);
		unlink(addr.sun_path);
		if(bind(fd, (struct sockaddr*)&addr, sizeof addr) < 0) die();
	}

	if(listen(fd, 100) < 0) die();
	locale_t l = newlocale(LC_ALL_MASK, "C", (locale_t)0);
	if(!l) die();

	openlog("musl-nscd", 0
#ifdef LOG_PERROR
			| LOG_PERROR
#endif
			, LOG_DAEMON);

	if(daemonize) {
		int null_fd = 0;
		if((null_fd = open("/dev/null", O_RDWR)) < 0) {
			syslog(LOG_ERR, "%s", strerror(errno));
			return 1;
		}
		if(dup2(null_fd, 0) < 0 || dup2(null_fd, 1) < 0 || dup2(null_fd, 2) < 0) {
			syslog(LOG_ERR, "%s", strerror(errno));
			return 1;
		}
		if(null_fd > 2) close(null_fd);

		switch(fork()) {
		case 0: break;
		case -1: syslog(LOG_ERR, "%s", strerror(errno)); return 1;
		default: return 0;
		}

		if(setsid() < 0) die();

		switch(fork()) {
		case 0: break;
		case -1: syslog(LOG_ERR, "%s", strerror(errno)); return 1;
		default: return 0;
		}
	}

	if(pid_path) {
		FILE *f = fopen(pid_path, "w");
		if(!f) { syslog(LOG_ERR, "%s", strerror(errno)); return 1; }
		fprintf(f, "%ju\n", (uintmax_t)getpid());
		fclose(f);
	}

	chdir("/");

	socket_handle(fd, -1, l, 0);
}
Example #23
0
/*
 *	process options
 */
void options(int argc, char *argv[])
{
	register char *s, *t;
	register int i;

	while (--argc > 0 && (*++argv)[0] == '-')
		for (s = argv[0] + 1; *s != '\0'; s++)
			switch (*s) {
			case 'o':
				if (*++s == '\0') {
					puts("name missing in option -o");
					usage();
				}
				if (out_form == OUTHEX)
					get_fn(objfn, s, OBJEXTHEX);
				else
					get_fn(objfn, s, OBJEXTBIN);
				s += (strlen(s) - 1);
				break;
			case 'l':
				if (*(s + 1) != '\0') {
					get_fn(lstfn, ++s, LSTEXT);
					s += (strlen(s) - 1);
				}
				list_flag = 1;
				break;
			case 's':
				if (*(s + 1) == '\0')
					sym_flag = 1;
				else if (*(s + 1) == 'n')
					sym_flag = 2;
				else if (*(s + 1) == 'a')
					sym_flag = 3;
				else {
					printf("unknown option -%s\n", s);
					usage();
				}
				s += (strlen(s) - 1);
				break;
			case 'x':
				dump_flag = 1;
				break;
			case 'f':
				if (*(s + 1) == 'b')
					out_form = OUTBIN;
				else if (*(s + 1) == 'm')
					out_form = OUTMOS;
				else if (*(s + 1) == 'h')
					out_form = OUTHEX;
				else {
					printf("unknown option -%s\n", s);
					usage();
				}
				s += (strlen(s) - 1);
				break;
			case 'd':
				if (*++s == '\0') {
					puts("name missing in option -d");
					usage();
				}
				t = tmp;
				while (*s)
					*t++ = islower((int)*s) ?
						toupper((int)*s++) : *s++;
				s--;
				*t = '\0';
				if (put_sym(tmp, 0))
					fatal(F_OUTMEM, "symbols");
				break;
			case 'v':
				ver_flag = 1;
				break;
			case 'e':
				if (*++s == '\0') {
					puts("symbol length missing in option -e");
					usage();
				}
				symlen = atoi(s);
				s += (strlen(s) - 1);
				break;
			default :
				printf("unknown option %c\n", *s);
				usage();
			}
	i = 0;
	while ((argc--) && (i < MAXFN)) {
		if ((infiles[i] = malloc(LENFN + 1)) == NULL)
			fatal(F_OUTMEM, "filenames");
		get_fn(infiles[i], *argv++, SRCEXT);
		i++;
	}
	if (i == 0) {
		printf("no input file\n");
		usage();
	}
}
Example #24
0
void process_file(char* file_path, char* output_path){
	unsigned long id = pthread_self();
	char* dummy, *log_path, *out_fn, *out_path, *decrypted, *log_entry, *line;
	int out;
	//Create and initialize strings
	char id_string[512];
	log_path = malloc(512);
	out_fn = malloc(512);
	out_path = malloc(512);
	log_entry = malloc(512);
	decrypted = malloc(512);
	id_string[0] = '\0';
	log_path[0] = '\0';
	out_fn[0] = '\0';
	out_path[0] = '\0';
	log_entry[0] = '\0';
	decrypted[0] = '\0';

	//Construct the log filepath
	strcpy(log_path, output_path);
	strcat(log_path, "/log.txt");
	//Construct the .out filename and path
	strcpy(out_fn, get_fn(file_path));
	strcat(out_fn, ".out");
	strcpy(out_path, output_path);
	strcat(out_path, "/");
	strcat(out_path, out_fn);
	//Construct the log entry
	sprintf(id_string, "%lu", id);
	strcpy(log_entry, file_path);
	strcat(log_entry, ": ");
	strcat(log_entry, id_string);

	//Write to the log
	out = open(log_path, O_CREAT | O_WRONLY | O_APPEND, OPEN_2);
	if(out == -1){
		fprintf(stderr, "ERROR: open() failure\n");
	}
	write(out, log_entry, strlen(log_entry));
	write(out, "\n", sizeof(char));
	close(out);

	//Extract and decrypt the data
	FILE* fp = file_open(file_path);
	if(fp == NULL){
		fprintf(stderr, "WARN: filepath is invalid\n");
		return;
	}
	line = malloc(512);
	line[0] = '\0';
	file_getline(line, fp);
	decrypt(decrypted, line);

	//Write to the .out file
	out = open(out_path, O_CREAT | O_WRONLY | O_TRUNC, OPEN_2);
	if(out == -1){
		fprintf(stderr, "ERROR: open() failure\n");
	}
	write(out, decrypted, strlen(decrypted));
	close(out);

	//Free pointers
	free(line);
	free(log_path);
	free(out_path);
	free(out_fn);
	free(log_entry);
	free(decrypted);
}
Example #25
0
void
ltspfs_write (int sockfd, XDR *in)
{
  XDR    out;
  char   path[PATH_MAX];
  char   output[LTSP_MAXBUF];
  int    i;
  int    fd;
  int    result;
  size_t size;
  off_t  offset;
  char   *buf;

  if (!xdr_u_int(in, &size)) {			/* Get the size */
    eacces(sockfd);
    return;
  }

  if (!xdr_longlong_t(in, &offset)) {		/* Get the offset */
    eacces(sockfd);
    return;
  }

  if (get_fn(sockfd, in, path)) {		/* Get the path */
    eacces(sockfd);
    return;
  }


  buf = malloc (size);

  /*
   * Check result of malloc
   */

  if (!buf) {
    status_return(sockfd, FAIL);
    return;
  }

  fd = open (path, O_WRONLY);
  if (fd == -1) {
    status_return(sockfd, FAIL);
    free (buf);
    return;
  }

  readn (sockfd, buf, size);

  lseek (fd, offset, SEEK_SET);
  result = write (fd, buf, size);

  if (result < 0)
    status_return(sockfd, FAIL);
  else {
    xdrmem_create(&out, output, LTSP_MAXBUF, XDR_ENCODE);
    i = 0;
    xdr_int(&out, &i);				/* dummy length */
    i = LTSP_STATUS_OK;				/* OK status */
    xdr_int(&out, &i);
    xdr_int(&out, &result);			/* Write out the result */
    i = xdr_getpos(&out);			/* Get current position */
    xdr_setpos(&out, 0);			/* rewind to the beginning */
    xdr_int(&out, &i);				/* re-write proper length */
    xdr_destroy(&out);				/* Clean up the XDR structs */

    if (debug)
      info("returning %s", output);

    writen(sockfd, output, i);
  }

  close (fd);

  free (buf);
}