I think that you don't know 3D position of the clicked point, because otherwise it would be easy :).
So if you know 3D position of the clicked point in origin basis then you can calculate far and near points like this:
nearPoint3D = cameraposition3D
farPoint3D = cameraposition3D + (normalize(clickedPoint3D - cameraposition3D) * zFar)
The problematic part is
clickedPoint3D. You can compute it nicely with help of view and projection matrices. As you are using opengl i suppose that you have them. view * projection matrix converts 3D points to the 2D screen space. You can use inverted viewprojection matrix and get matrix which converts 2D screen points to the 3D space.
pseudo code and some openGl:
//read projection matrix
gluPerspective(...); //your perspective function
glGetFloatv(GL_PROJECTION_MATRIX, &g_CameraProjectionMatrix.m); //returns matrix as float array
//read view matrix
glLookAt(...); //you lookat function or whatever - NO translation,rotations or anything else for getting camera matrix!
//compute 3D position of clicked point
Matrix4x4 viewProjInv = (g_LightViewMatrix * g_CameraViewMatrix).getInverse();
vector4D clickedPointOnSreen = (x_screen,y_screen,1.0f,1.0f); // Z have to be between 0 - 1 and W have to be 1
vector4D clickedPointIn3DOrigin = viewProjInv * clickedPointOnSreen;
vector3D clickedPoint3D = clickedPointIn3DOrigin.xyz;
Note that you can use this to compute 3D points of zNear and zFar really easily:
vector4D clickedPointOnSreen = (x_screen,y_screen,1.0f,1.0f); // will produce 3D position of zFar
vector4D clickedPointOnSreen = (x_screen,y_screen,0.0f,1.0f); // will produce 3D position of zNear.
Isn't that algebra wonderful? :)
To learn something about projection matrix you can read this what-is-the-purpose-of-the-canonical-view-volume